AWS Certified Developer – Associate (DVA-C02)DeploymentMedium
A developer is deploying a containerized application to Amazon ECS using AWS Fargate. They want to ensure that the application's configuration, such as database connection strings and API keys, can be easily updated without rebuilding the Docker image or redeploying the entire service. The configuration should be accessible by the containers at runtime. Which approach should the developer take?
- AUse AWS CodeCommit to manage configuration files and pull them at runtime.
- BStore configuration in environment variables within the Task Definition.
- CMount an Amazon EFS file system to store configuration files.
- DEmbed configuration directly into the Dockerfile at build time.
Show answer & explanationAnswer & explanation
Correct answer: B. Store configuration in environment variables within the Task Definition.
Storing configuration in environment variables within the ECS Task Definition is a standard and secure way to provide runtime configuration to Fargate containers. This allows updates without rebuilding images and can integrate with Secrets Manager for sensitive data.
Why the other options are wrong
- A. Pulling from CodeCommit at runtime adds complexity and is not the idiomatic way to manage application configuration in ECS.
- C. EFS is for persistent shared storage, not typically for ephemeral application configuration like connection strings, and adds network overhead and complexity.
- D. Embedding in Dockerfile requires image rebuilds for every configuration change, which is inefficient.
ECS Task Definition Environment Variables
Within an Amazon ECS Task Definition, you can define environment variables that are passed to your containers at runtime. This allows for dynamic configuration without modifying the container image, supporting different environments and sensitive data management.
- Passes configuration to containers at runtime.
- Updates don't require image rebuilds.
- Supports different configurations per environment.
- Can be integrated with Secrets Manager for sensitive data.
Memory trick: Task Definition's ENV variables: the container's dynamic brain.