A developer is deploying an update to a Python application hosted on AWS Elastic Beanstalk using the Amazon Linux 2023 platform. The deployment requires running a database migration script that is packaged inside the application source code. This script must run after the application source archive is extracted to the staging directory, but before the application version is deployed and the web server is restarted. Which approach should the developer use to run the script at the correct stage?
- Place the migration script in the .platform/hooks/predeploy/ directory of the application source bundle.Cevap
- BPlace the migration script in the .ebextensions/ directory and configure it under the commands section of a configuration file.
- CPlace the migration script inside a directory named ebextensions/ (without a leading dot) at the root of the source bundle.
- DPlace the migration script in the root directory and specify its execution in the BeforeInstall hook of an appspec.yml file.
Cevap
Place the migration script in the .platform/hooks/predeploy/ directory of the application source bundle.
The correct answer is to place the script in the .platform/hooks/predeploy/ directory. In modern Elastic Beanstalk platforms (Amazon Linux 2 and Amazon Linux 2023), developers can run custom scripts at specific lifecycle events using platform hooks. Scripts placed in the .platform/hooks/predeploy/ folder are executed after the application archive is extracted to the staging folder but before the application version is deployed and the web server is restarted. This is the correct phase for running database migrations or setting up environment-specific configuration files.
Adım Adım Çözüm
Anahtar Kavram
AWS Elastic Beanstalk Platform Hooks
Tahmini Süre:1m 30s