An organization is transitioning a containerized API from Amazon EC2 to Amazon ECS and implementing blue/green deployments using AWS CodeDeploy. A developer must configure the deployment to execute an AWS Lambda function named "ValidateDeployment" to run smoke tests on the replacement task set after it is provisioned but before any traffic is routed to it. The validation Lambda function must also retrieve database credentials from AWS Secrets Manager during its run. Which configuration represents the correct setup for the AppSpec file and the required IAM roles to support this deployment?
- AUse an AppSpec file with lowercase resources and hooks sections, defining the Lambda function ARN under hooks as `- AfterInstall: "arn:aws:lambda:us-east-1:123456789012:function:ValidateDeployment"`. Configure the Amazon ECS Task Execution Role with a trust policy for ecs-tasks.amazonaws.com, and grant it AWS Secrets Manager retrieve permissions.
- BUse an AppSpec file with capitalized Resources and Hooks sections, defining the Lambda function ARN under Hooks as `- AfterInstall: "arn:aws:lambda:us-east-1:123456789012:function:ValidateDeployment"`. Configure the CodeDeploy service role to trust codedeploy.amazonaws.com. Grant the CodeDeploy service role permissions to retrieve the database credentials from Amazon Systems Manager Parameter Store, as CodeDeploy will retrieve and inject the credentials.
- Use an AppSpec file with capitalized Resources and Hooks sections, defining the Lambda function ARN under Hooks as `- AfterInstall: "arn:aws:lambda:us-east-1:123456789012:function:ValidateDeployment"`. Configure the AWS CodeDeploy service role with a trust policy that allows codedeploy.amazonaws.com to assume the role. Grant the validation Lambda function's execution role permission to retrieve the database credentials from AWS Secrets Manager.Answer
- DUse an AppSpec file with lowercase files and hooks sections, defining a shell script under hooks as `- ApplicationStart: "scripts/validate.sh"`. Configure the Amazon EC2 Instance Profile role to trust codedeploy.amazonaws.com. Grant the EC2 Instance Profile role permission to retrieve the database credentials from AWS Secrets Manager.
Answer
The correct configuration is to use capitalized Resources and Hooks sections in the AppSpec file, define the validation Lambda function under the AfterInstall hook, configure the AWS CodeDeploy service role to trust codedeploy.amazonaws.com, and grant the validation Lambda function's IAM execution role permission to retrieve the credentials from AWS Secrets Manager.
The correct option correctly identifies that for ECS deployments, the AppSpec file must contain capitalized Resources and Hooks sections, and the validation hook must be a Lambda function defined under a valid ECS hook like AfterInstall. It also correctly specifies that the CodeDeploy service role trust policy must trust codedeploy.amazonaws.com, and the validation Lambda function's execution role must be granted Secrets Manager permissions to retrieve database credentials.
Step-by-Step Solution
Key Concept
AWS CodeDeploy AppSpec lifecycle hooks and IAM configuration requirements for Amazon ECS blue/green deployments.
Estimated Time:2m 30s