A developer is migrating a containerized web application from Amazon EC2 instances to Amazon ECS. The deployment process is managed by AWS CodeDeploy using a Blue/Green deployment configuration. Before production traffic is shifted to the replacement task set, the deployment must execute a database migration script. This script retrieves a database password that must be automatically rotated every 30 days.
The developer writes the following `appspec.yaml` file for the Amazon ECS service:
yaml
version: 0.0
Resources:
- TargetService:
Type: AWS::ECS::Service
Properties:
TaskDefinition: "arn:aws:ecs:us-east-1:111122223333:task-definition/my-app:1"
LoadBalancerInfo: ContainerName: "web"
ContainerPort: 80
Hooks:
- AfterInstall:
- location: "scripts/migrate.sh"
timeout: 600
Which set of actions must the developer perform to ensure the database migration runs successfully and complies with the rotation requirement?
- Package the database migration script into an AWS Lambda function and update the `AfterInstall` hook in the `appspec.yaml` to reference the Lambda function's ARN. Store the database password in AWS Secrets Manager with automatic rotation enabled, and grant the Lambda function's execution role permissions to retrieve the secret.Answer
- BKeep the `appspec.yaml` hooks structure as is to run the migration script directly, but update the Amazon ECS task execution role's trust policy to trust `codedeploy.amazonaws.com`. Store the password in AWS Systems Manager Parameter Store as a SecureString with native automatic rotation enabled.
- CChange the hook in the `appspec.yaml` from `AfterInstall` to `ValidateService` to run the migration script, and keep the shell script location path. Store the database password in AWS Systems Manager Parameter Store, and configure an Amazon EventBridge rule to trigger a custom rotation Lambda function.
- DPackage the database migration script into an AWS Lambda function and update the `AfterInstall` hook to reference the Lambda function's ARN. Store the database password in AWS Systems Manager Parameter Store, and configure the Lambda function's trust policy to trust `codedeploy.amazonaws.com` so CodeDeploy can assume the function role directly.