A developer is configuring AWS CodeDeploy to deploy a Python web application to a fleet of Amazon EC2 instances. The deployment process must retrieve database credentials securely from AWS Systems Manager Parameter Store (stored as a `SecureString` parameter) and execute a database migration script before the application starts and begins accepting traffic.
Which two actions must the developer perform to meet these requirements?
- Grant the Amazon EC2 instance profile IAM role the `ssm:GetParameters` and `kms:Decrypt` permissions.Answer
- Execute the database migration script during the `AfterInstall` lifecycle hook in the `appspec.yml` file.Answer
- CExecute the database migration script during the `BeforeAllowTraffic` lifecycle hook in the `appspec.yml` file.
- DGrant the AWS CodeDeploy service role the `ssm:GetParameters` and `kms:Decrypt` permissions.
- EDefine the Parameter Store parameters in the `resources` section of the `appspec.yml` file to inject them as environment variables.
Answer
Granting the Amazon EC2 instance profile IAM role the necessary decrypt permissions and executing the migration script during the AfterInstall lifecycle hook in the appspec.yml file.
To successfully run the database migration before the application starts, the script must execute during a valid EC2 lifecycle hook like `AfterInstall`. Since the script runs on the EC2 instances, the instance profile IAM role must have permissions to retrieve the SecureString parameter and decrypt it using the associated KMS key.
Step-by-Step Solution
Key Concept
AWS CodeDeploy EC2 deployments rely on the CodeDeploy agent running under the instance profile's IAM permissions and execute scripts within EC2-specific lifecycle hooks such as AfterInstall.
Estimated Time:2m 0s