DVA-C02 Question 217
Single answerYou are developing a Node.js application that will be deployed to an Auto Scaling group of Amazon EC2 instances. The application requires specific environment variables to be set, and static assets such as images and CSS files need to be included. What is the BEST way to prepare the application artifacts for deployment to ensure consistency and reusability?
- A
Package the application code, environment variables, and static assets into a ZIP file and upload it to an S3 bucket.
- B
Use AWS Elastic Beanstalk to directly upload the application code and environment variables without packaging.
- C
Build a Docker image containing the application, environment variables, and static assets, and push it to Amazon Elastic Container Registry (ECR).
- D
Manually upload the static assets to Amazon S3 and configure the application to fetch them at runtime.
Show answer and explanation
Correct answer: C
Explanation
When deploying applications to an Auto Scaling group, using Docker images is a best practice. A Docker image allows you to bundle your application code, environment variables, and static assets into a single, consistent artifact. Pushing the image to Amazon Elastic Container Registry (ECR) makes it easy to pull the image during deployment, ensuring that every instance in the group has an identical runtime environment.
- A. Incorrect.
Packaging the application into a ZIP file and uploading to an S3 bucket is a common practice for Lambda functions, but for EC2 Auto Scaling groups, using Docker images ensures a more consistent and reusable deployment process.
- B. Incorrect.
Using Elastic Beanstalk to directly upload the application can be a valid approach for deployment, but it does not ensure consistency and reusability in scenarios where you require more control over the runtime environment.
- C. Correct.
Building a Docker image and pushing it to Amazon ECR is the best approach in this scenario. It allows you to encapsulate the application code, environment variables, and static assets in a consistent and reusable way, making it suitable for deployment to an Auto Scaling group.
- D. Incorrect.
Manually uploading static assets to S3 and fetching them at runtime introduces additional complexity and does not address the need to package the application code and environment variables consistently.