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?
- 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
- BThe 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.
- CThe validation Lambda function's IAM execution role contains a trust policy that trusts the CodeDeploy service instead of the Lambda service.
- DThe 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
Key Concept
AWS CodeDeploy AppSpec lifecycle hooks for AWS Lambda deployments