Q48 — AWS DOP-C02 Ch.3
Question 48 of 100 | ← Chapter 3
A company uses AWS CodeDeploy to automate deployments of a Java-Apache Tomcat application running on Apache web servers. The development team has completed initial setup, creating a deployment group for the development environment and performing functional testing within the application. Next, the team will create additional deployment groups for staging and production.
- A. Tag Amazon EC2 instances according to the deployment group. Then include a script in the application revision that calls the metadata service and EC2 API to determine which deployment group the instance belongs to. Use this information to configure log level settings. Reference this script in the appspec.yml file as part of the AfterInstall lifecycle hook.
- B. Create a script that uses the CodeDeploy environment variable DEPLOYMENT_GROUP_NAME to identify which deployment group the instance belongs to. Use this information to configure log level settings. In the appspec.yml file, reference this script as part of the BeforeInstall lifecycle hook. ✓
- C. Create a CodeDeploy custom environment variable for each environment. Then place a script in the application revision that checks this environment variable to determine which deployment group the instance belongs to. Use this information to configure log level settings. In the appspec.yml file, reference this script as part of the ValidateService lifecycle hook.
- D. Create a script that uses the CodeDeploy environment variable DEPLOYMENT_GROUP_ID to identify which deployment group the instance belongs to, to configure log level settings. Reference this script in the appspec.yml file as part of the Install lifecycle hook.
Correct Answer: B. Create a script that uses the CodeDeploy environment variable DEPLOYMENT_GROUP_NAME to identify which deployment group the instance belongs to. Use this information to configure log level settings. In the appspec.yml file, reference this script as part of the BeforeInstall lifecycle hook.
Explanation
AWS CodeDeploy provides built-in environment variables such as DEPLOYMENT_GROUP_NAME, which can be accessed directly by scripts during deployment. AWS documentation confirms CodeDeploy injects these variables automatically without extra configuration. Option B triggers the script during the BeforeInstall phase and uses the environment variable to dynamically configure log levels—avoiding separate script versions or custom environment variables. Option A adds complexity and permissions overhead via EC2 metadata and API calls; Option C increases maintenance burden with custom environment variables; Option D’s DEPLOYMENT_GROUP_ID is not a documented standard CodeDeploy environment variable. Option B meets the minimal management overhead requirement using natively supported variables.