Q24 — AWS DOP-C02 Ch.2
Question 24 of 100 | ← Chapter 2
A company uses AWS CodeDeploy to automate deployments of a Java-Apache Tomcat application running on Apache web servers. The development team begins with a proof-of-concept, creating a deployment group for the development environment and performing functional tests in that environment. After successful validation, the team will create additional deployment groups for staging and production. Currently, log levels are configured in Apache settings, but the team wants to dynamically adjust this configuration during deployment so they can set different log levels per deployment group without requiring separate application revisions for each group. How can these requirements be met with minimal administrative overhead and without using different script versions per deployment group?
- A. Tag Amazon EC2 instances by deployment group. Then embed a script in the application revision that calls the metadata service and EC2 API to identify which deployment group the instance belongs to. Use this information to configure the log level setting. Reference the 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 the log level setting. Reference this script in the appspec.yml file as part of the BeforeInstall lifecycle hook. ✓
- C. Create a CodeDeploy custom environment variable for each environment. Embed 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 the log level setting. Reference this script in the appspec.yml file 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 the log level setting. 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 the log level setting. Reference this script in the appspec.yml file as part of the BeforeInstall lifecycle hook.
Explanation
In this scenario, the team wants to dynamically configure Apache log levels based on the deployment group, without maintaining separate application revisions or script versions per group. Option B uses the CodeDeploy environment variable `DEPLOYMENT_GROUP_NAME` to identify the deployment group and configure log levels accordingly. This approach allows a single script and application revision to adapt across deployment groups, minimizing administrative overhead. Placing the script in the `BeforeInstall` lifecycle hook ensures log level configuration is applied before the application is installed—meeting the requirement. Thus, Option B is correct.