Ask
Ask

Reputation: 3746

AWS ECS specify configuration file based on environment

I have two applications (.net core 3.1 and Angular 8) which are deployed on aws ecs as a docker containers. Now I want to setup multiple environments e.g quality, staging, production etc. Now I want read data from specific configuration file so that for staging docker container will read data from appsettings.staging.json and for production, it will read data from appsettings.production.json. Same for Angular.

How can I do that? I can specify environment variables in codebuild in aws but how can I tell docker to read specific files?

Upvotes: 0

Views: 2617

Answers (2)

shariqmaws
shariqmaws

Reputation: 8890

Some random thoughts:

  1. Create different ECS clusters for different environments (UAT/DEV/PROD).
  2. Use same docker image for different environments (no rebuilding images per environment)
  3. Pull secrets/configuration from Parameter store [1] or Secrets Manager [2]
  4. Keep versioned config file in S3 or Git and pull it down when container is initialised. Dont bake config with images. Better yet, no config files and everything read from Environment variables. Look for solutions like confd (https://github.com/kelseyhightower/confd)
  5. Generally look to follow: https://12factor.net/

Ref:

[1] https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html

[2] https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data-tutorial.html

Upvotes: 1

Robert Moskal
Robert Moskal

Reputation: 22553

There are a number of ways to skin this cat. They all involve creating a separate task definition for each environment (all using the same container).

You can pass different environment variables into each task definition (or mount different volumes).

You could package all the config files in your container, and have an environment variable that points at the proper file for each environment.

There are other options that wouldn't require packaging all the configs in the docker file. This has advantages since you don't need to rebuild the container when you change the config.

You could put all the configs in environment variables, use the AWS secrets manager, or mount a different volume with the config for each task definition.

Upvotes: 0

Related Questions