Question

Difficulty: HardAWS CodeDeploy

A developer is configuring a deployment to shift traffic to a new version of an AWS Lambda function using AWS CodeDeploy. The deployment group is configured with an IAM service role. When the deployment is initiated, the developer encounters an error during the initial validation of the AppSpec file, and the deployment is aborted. The AppSpec file is configured as follows:

yaml
version: 0.0
Resources:
- MyLambdaFunction:
Type: AWS::Lambda::Function
Properties:
Name: "MyServiceFunction"
Alias: "live"
CurrentVersion: "1"
TargetVersion: "2"
Hooks:
- BeforeInstall: "ValidationFunction"

What is the reason for this deployment failure?

  1. The AppSpec file specifies 'BeforeInstall' under the 'Hooks' section, which is a lifecycle hook reserved for EC2/on-premises and ECS deployments and is invalid for AWS Lambda deployments.Answer
  2. B
    The service role configured for the CodeDeploy deployment group has a trust policy that allows the assume role action for the Lambda service instead of the CodeDeploy service.
  3. C
    The validation Lambda function's IAM execution role contains a trust policy that trusts the CodeDeploy service instead of the Lambda service.
  4. D
    The validation function attempts to retrieve configurations from Systems Manager Parameter Store using a standard parameter instead of Secrets Manager, violating CodeDeploy's encryption policies.

Answer

The AppSpec file specifies 'BeforeInstall' under the 'Hooks' section, which is a lifecycle hook reserved for EC2/on-premises and ECS deployments and is invalid for AWS Lambda deployments.
The correct option is correct because AWS CodeDeploy deployments for the Lambda compute platform only support the 'BeforeAllowTraffic' and 'AfterAllowTraffic' lifecycle hooks. Hook names such as 'BeforeInstall', 'AfterInstall', and 'AfterAllowTestTraffic' are invalid for Lambda deployments (though they are valid for ECS or EC2/on-premises deployments). Specifying an invalid hook causes the AppSpec validation to fail before the deployment can proceed.

Step-by-Step Solution

1
Inspect the resources and hooks sections of the AppSpec file.
Identify that the resource type is 'AWS::Lambda::Function' and the hook is 'BeforeInstall'.
AWS CodeDeploy supports different hooks depending on the target compute platform.
2
Recall the valid lifecycle hooks for AWS Lambda deployments in AWS CodeDeploy.
Lambda deployments only support 'BeforeAllowTraffic' and 'AfterAllowTraffic'.
Other hooks like 'BeforeInstall' are only applicable to EC2/on-premises or ECS platforms.
3
Identify why the validation failed based on the hook mismatch.
The presence of 'BeforeInstall' causes the AppSpec validation to fail immediately.
CodeDeploy rejects AppSpec files containing invalid hooks for the specified resource type.

Key Concept

AWS CodeDeploy AppSpec lifecycle hooks for AWS Lambda deployments
Rate this question