Question

Difficulty: MediumAWS CodeDeploy

A developer is configuring the `appspec.yml` file for an AWS Lambda deployment using AWS CodeDeploy. The deployment needs to shift traffic to a new version of a function. The developer wants to run validation tests before the traffic shift starts, and a notification function after all traffic has successfully shifted. The developer begins drafting the AppSpec file as follows:

yaml
version: 0.0
Resources:
- MyLambdaFunction:
Type: AWS::Lambda::Function
Properties:
Name: "MyLambdaFunction"
Alias: "live"
CurrentVersion: "1"
TargetVersion: "2"
Hooks:
- Hook_1: "ValidationLambdaFunction"
- Hook_2: "NotificationLambdaFunction"

Which of the following lifecycle hooks are valid replacements for `Hook_1` and `Hook_2` to meet these requirements? (Select TWO.)

  1. BeforeAllowTrafficAnswer
  2. AfterAllowTrafficAnswer
  3. C
    ValidateService
  4. D
    BeforeInstall
  5. E
    AfterInstall

Answer

BeforeAllowTraffic and AfterAllowTraffic
For AWS Lambda deployments, AWS CodeDeploy supports only two lifecycle hooks: BeforeAllowTraffic and AfterAllowTraffic. The hook BeforeAllowTraffic executes validation tasks before any traffic starts shifting, and AfterAllowTraffic executes tasks after all traffic has shifted to the new version.

Step-by-Step Solution

1
Identify the target compute platform for the CodeDeploy deployment based on the AppSpec schema.
The platform is AWS Lambda, indicated by the 'AWS::Lambda::Function' type under 'Resources'.
AWS CodeDeploy supports different lifecycle hooks depending on whether the target is EC2/On-premises, ECS, or Lambda.
2
Determine the supported lifecycle hooks for AWS Lambda deployments.
Only BeforeAllowTraffic and AfterAllowTraffic are valid lifecycle hooks for AWS Lambda in CodeDeploy.
Unlike EC2 or ECS, Lambda deployments only support hooks that run immediately before traffic shifting begins and immediately after traffic shifting completes.
3
Map the requirements (validation before shifting and notifications after shifting) to the corresponding hooks.
Hook_1 (validation before shifting) maps to BeforeAllowTraffic, and Hook_2 (notification after shifting) maps to AfterAllowTraffic.
BeforeAllowTraffic executes tasks before the first increment of traffic shifts to the new version, while AfterAllowTraffic runs after the final increment has shifted.

Key Concept

AWS CodeDeploy lifecycle hooks for AWS Lambda deployments
Estimated Time:1m 30s
Rate this question