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 Value as something.cloud.com

  • Using customized AMI in Elastic Beanstalk (Multi-container Docker) via awsebcli
  • Deploying multi-docker local setup to AWS using Elastic Beanstalk
  • Automatic way to pick up the hostname inside docker container
  • Can I configure ECS to automatically purge old container [images] from my EC2 instances?
  • Mesos/Marathon on EC2 agents hostnames not accessible
  • AWS EC2 Container Service / Elastic Beanstalk Docker Container Port udp binding
  • on my local I use this docker run command and I ma able to pass in my env variables, but through task definition the variables are not being passed to container.

    This docker run command that works on local how to set it up in task definition in AWS ECS:

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

  • How to make docker containers host-agnostic
  • Docker automated build results in Unexpected failure
  • Kubernetes how to make Deployment to update image
  • access data volume of node modules outside docker container
  • Building a new docker image with the same name as an existing ones
  • What is the relationship between a docker image ID and the IDs in the manifests?
  • 2 Solutions collect form web for “how to provide environment variables to AWS ECS task definition?”

    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"
        }
        ]
     }
    

    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.
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.