Soru

Zorluk: KolayAWS CodeDeploy

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?

  1. A
    Modify the trust policy of the EC2 instance profile to allow the EC2 service to assume the CodeDeploy service role.
  2. B
    Store the script in AWS Secrets Manager and configure automatic rotation to run it during deployment.
  3. Define the script path under the AfterInstall event in the hooks section of the appspec.yml file.Cevap
  4. D
    Define the script path under the AfterAllowTraffic event in the resources section of the appspec.yml file.

Cevap

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.

Adım Adım Çözüm

1
Identify the target compute platform for the CodeDeploy deployment.
The target compute platform is Amazon EC2.
Different compute platforms (EC2 vs ECS/Lambda) have different AppSpec file structures and lifecycle hooks.
2
Select the correct section in the AppSpec file for Amazon EC2 deployments.
The 'hooks' section is used for EC2 deployments, whereas the 'resources' section is used for ECS/Lambda.
EC2 deployments use the 'hooks' section to execute scripts during deployment lifecycle events.
3
Choose the appropriate lifecycle hook that executes after file copying but before application startup.
The 'AfterInstall' hook runs right after the files are copied, which is before the application service starts.
This meets the requirement of running the initialization script immediately after file copy and before startup.

Anahtar Kavram

AWS CodeDeploy AppSpec lifecycle hooks for EC2 deployments require using the 'hooks' section and the 'AfterInstall' event to run scripts after files are copied.
Bu soruyu puanla