Soru

Zorluk: KolayAWS CodeDeploy

A developer needs to run a database migration script on Amazon EC2 instances before the new application files are copied during an AWS CodeDeploy deployment. Which configuration file and lifecycle hook should the developer use to execute this script?

  1. A
    A buildspec.yml file in the root directory, running the script in the pre_build phase
  2. B
    An appspec.yml file in the root directory, running the script in the BeforeAllowTraffic hook
  3. An appspec.yml file in the root directory, running the script in the BeforeInstall hookCevap
  4. D
    A configuration file in the .ebextensions directory, running the script in container_commands

Cevap

An appspec.yml file in the root directory, running the script in the BeforeInstall hook
AWS CodeDeploy manages EC2/On-Premises deployments using the appspec.yml file located in the root of the source directory. In this file, the developer can define hooks to run scripts at specific phases. The BeforeInstall hook is the appropriate hook to execute scripts (such as database migrations or clearing temp folders) before the actual application files are copied to the instance during the installation phase.

Adım Adım Çözüm

1
Identify the service responsible for orchestrating the deployment to Amazon EC2.
The deployment is orchestrated by AWS CodeDeploy.
AWS CodeDeploy requires a configuration file named appspec.yml at the root of the source bundle to define deployment lifecycle hooks.
2
Determine the correct lifecycle hook for running tasks before files are copied.
The BeforeInstall hook is executed prior to the installation phase where files are copied to the target directory.
For EC2/On-Premises deployments, the AppSpec lifecycle sequence runs ApplicationStop -> BeforeInstall -> Install -> AfterInstall -> ApplicationStart -> ValidateService. Therefore, running a script before files are copied requires using BeforeInstall.

Anahtar Kavram

AWS CodeDeploy AppSpec lifecycle hooks for EC2 deployments
Bu soruyu puanla