A developer is configuring AWS CodeDeploy to deploy a web application to a fleet of Amazon EC2 instances. The deployment must copy application files to the target instances and run a shell script (scripts/initialize.sh) that installs application dependencies. During execution, this script must download a configuration file from a secured Amazon S3 bucket.
Which two options must the developer configure to meet these requirements? (Select TWO.)
- Define the script path and execution settings under the AfterInstall lifecycle hook in the hooks section of the appspec.yml file.Cevap
- Attach an IAM instance profile to the Amazon EC2 instances with a policy that allows the s3:GetObject action on the target S3 bucket.Cevap
- CDefine the script path and execution settings under the BeforeAllowTraffic lifecycle hook in the hooks section of the appspec.yml file.
- DAttach an IAM policy to the CodeDeploy service role that allows the s3:GetObject action on the target S3 bucket.
- EStore the configuration file in AWS Secrets Manager and grant the CodeDeploy service role permission to rotate the secret during the ValidateService hook.
Cevap
Define the script path and execution settings under the AfterInstall lifecycle hook in the appspec.yml file, and attach an IAM instance profile to the Amazon EC2 instances with a policy that allows the s3:GetObject action on the target S3 bucket.
The correct options are to define the script execution under the AfterInstall hook in the appspec.yml file and to attach an S3 read permission policy to the EC2 instance profile. The AfterInstall hook is a standard EC2 deployment lifecycle hook suitable for post-installation tasks like installing dependencies. Because the CodeDeploy agent runs directly on the EC2 instances, any commands executed by the agent (such as scripts in the hooks section) run under the security context of the EC2 instance. Therefore, the instance profile attached to the EC2 instances must have permissions to access the S3 bucket.
Adım Adım Çözüm
Anahtar Kavram
Understanding AWS CodeDeploy EC2 lifecycle hooks and how IAM permissions are resolved for scripts executed by the CodeDeploy agent on EC2 instances.