An engineering team is implementing canary deployments for an AWS Lambda function using AWS CodeDeploy. They define the following `appspec.yaml` file to run validation tests on the new function version before traffic is shifted:
yaml
version: 0.0
Resources:
- myLambdaFunction:
Type: AWS::Lambda::Function
Properties:
Name: "myLambdaFunction"
Alias: "live"
CurrentVersion: "1"
TargetVersion: "2"
Hooks:
- BeforeAllowTraffic: "RunSanityCheck"
The CodeDeploy service role has the AWS-managed policy `AWSCodeDeployRoleForLambda` attached. During execution, the deployment immediately fails at the `BeforeAllowTraffic` lifecycle hook event.
Which of the following is the correct explanation for this deployment failure?
- The CodeDeploy service role lacks permissions to invoke the validation function because the AWS-managed policy restricts `lambda:InvokeFunction` to functions prefixed with `CodeDeployHook_`.Answer
- BThe validation function must be specified under the `BeforeInstall` hook in the `appspec.yaml` file, as the `BeforeAllowTraffic` hook is only supported on Amazon EC2 deployments.
- CThe validation function's IAM execution role trust policy does not permit the CodeDeploy service principal (`codedeploy.amazonaws.com`) to assume the role.
- DThe validation function is attempting to retrieve database credentials from AWS Systems Manager Parameter Store, but the AppSpec file must define these secrets in the resources section for CodeDeploy to inject them.
Answer
The CodeDeploy service role lacks permissions to invoke the validation function because the AWS-managed policy restricts `lambda:InvokeFunction` to functions prefixed with `CodeDeployHook_`.
The standard AWS-managed policy `AWSCodeDeployRoleForLambda` restricts the `lambda:InvokeFunction` permission to functions whose names start with the prefix `CodeDeployHook_`. Because the validation function is named `RunSanityCheck`, the CodeDeploy service role is not authorized to invoke it, leading to a failure during the `BeforeAllowTraffic` hook execution and triggering an automatic rollback.
Step-by-Step Solution
Key Concept
AWS CodeDeploy Lambda Hook Validation Permissions
Estimated Time:2m 0s