Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to provide environment variables to AWS ECS task definition?

Tags:

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

Key as HOST_NAME and 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

like image 420
governingcloud Avatar asked Apr 10 '17 18:04

governingcloud


People also ask

How can I see environment variables in ECS?

Environment variables are defined inside the container and some are passed in the task definition. So you can use describe-task-definition to see the extra variables.

WHAT IS environment in task definition?

Environment variables specified in the task definition are readable by all IAM users and roles that are allowed the DescribeTaskDefinition action for the task definition. Environment variable files are objects in Amazon S3 and all Amazon S3 security considerations apply. See the below section Required IAM permissions.

What are the mandatory parameters in the task definition in ECS?

The family and container definitions are required in a task definition. In contrast, task role, network mode, volumes, task placement constraints, and launch type are optional. You can use these parameters in a JSON file to configure your task definition.

How do I use an environment variable in AWS?

To set environment variablesSign in to the AWS Management Console and open the Amplify console . In the Amplify console, choose App Settings, and then choose Environment variables. In the Environment variables section, choose Manage variables. In the Manage variables section, under Variable, enter your key.


1 Answers

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"     }     ]  } 
like image 86
Chris Avatar answered Sep 26 '22 01:09

Chris