A developer is deploying a web application to Amazon EC2 instances using AWS CodeDeploy. The developer needs to execute a script named initialize.sh immediately after the application files are copied to the target instances, but before the application service starts. Which configuration action should the developer take to accomplish this?
- AModify the trust policy of the EC2 instance profile to allow the EC2 service to assume the CodeDeploy service role.
- BStore the script in AWS Secrets Manager and configure automatic rotation to run it during deployment.
- Define the script path under the AfterInstall event in the hooks section of the appspec.yml file.Answer
- DDefine the script path under the AfterAllowTraffic event in the resources section of the appspec.yml file.
Answer
Define the script path under the AfterInstall event in the hooks section of the appspec.yml file.
Defining the script path under the AfterInstall event in the hooks section of the appspec.yml file is the correct way to execute scripts on Amazon EC2 instances immediately after files are copied, but before the application starts.
Step-by-Step Solution
Key Concept
AWS CodeDeploy AppSpec lifecycle hooks for EC2 deployments require using the 'hooks' section and the 'AfterInstall' event to run scripts after files are copied.