governingcloud
governingcloud

Reputation: 385

how to provide environment variables to AWS ECS task definition?

In the task definition on ECS, I have provided environment variable as following:

Key as HOST_NAME and the value as something.cloud.com

On my local I use this docker run command and I'm able to pass in my env variables, but through task definition the variables are not being passed to container.

The docker run command below works on local, but how do I set it up in the task definition in AWS ECS?

docker run -e HOST_NAME=something.cloud.com sid:latest

Upvotes: 26

Views: 49033

Answers (3)

Kaka Ruto
Kaka Ruto

Reputation: 5125

If you used the new docker compose integration with ECS, then you will need to update the stack.

It is smart enough to update only the parts that changed. For my case, this was the task definition not picking new environment variables set on a .env file and mounted on the docker container

Run the same command you used to create the stack, only that this time round it'll update it(only parts that changed)

docker compose --context you-ecs-context up -f your.docker-compose.yml

For more: https://docs.docker.com/engine/context/ecs-integration/#rolling-update

Upvotes: 1

Ivan Sukhomlyn
Ivan Sukhomlyn

Reputation: 1

You can set hostname var at task definition JSON file

hostname
Type: string

Required: no

The hostname to use for your container. This parameter maps to Hostname in the Create a container section of the Docker Remote API and the --hostname option to docker run.

Upvotes: -6

Chris
Chris

Reputation: 3865

You should call it name and not key, see example below

 {
  "name": "nginx",
  "image": "",
  "portMappings": [
    {
      "containerPort": 80,
      "hostPort": 80
    }
  ],
  "environment": [
    {
      "name": "HOST_NAME",
      "value": "something.cloud.com"
    }
    ]
 }

Upvotes: 34

Related Questions