DVA-C02 Question 201
Single answerYou are deploying a Node.js application to AWS Elastic Beanstalk. The application requires a database connection string, which should not be hardcoded into the application's source code for security purposes. How can you inject the database connection string into the application in a secure and manageable way?
- A
Define the database connection string as an environment variable in the Elastic Beanstalk environment configuration.
- B
Include the database connection string in the application's source code and upload it to Elastic Beanstalk.
- C
Store the database connection string in an AWS Secrets Manager secret and fetch it dynamically within the application.
- D
Use an EC2 instance metadata endpoint to retrieve the database connection string at runtime.
Show answer and explanation
Correct answer: A
Explanation
Environment variables are a secure and manageable way to inject sensitive information, like database connection strings, into applications running on AWS Elastic Beanstalk. This keeps the sensitive data out of the application’s source code and allows for centralized management directly in the Elastic Beanstalk environment configuration.
- A. Correct.
This is the correct approach. Elastic Beanstalk allows you to define environment variables in its environment configuration, which can then be accessed by the application. This keeps sensitive information out of the source code while making it manageable.
- B. Incorrect.
This is insecure and not recommended because it exposes sensitive information to anyone with access to the source code.
- C. Incorrect.
While AWS Secrets Manager is a secure option for storing secrets, this approach would require additional setup and is not directly supported by Elastic Beanstalk's native environment variable configuration mechanism.
- D. Incorrect.
The EC2 instance metadata endpoint is not designed for securely retrieving application-specific secrets like database connection strings.