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

  • Where are the source files for my Docker application deployed to ECS?
  • Python/Django Elastic Beanstalk now failing on deploy
  • Docker swarm security and high availability on AWS
  • docker run mongo image on a different port
  • AWS UDP High Availability
  • Error Docker deployment in Amazon EC2 - Docker container quit unexpectedly
  • 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 sid:latest

  • Why does “bundle install --path” break when “bundle install” works?
  • Pass command line arguments to Docker with Ansible
  • For every build , how to spin up Jenkins slave container that has a docker host on it
  • Establish PSSession to Windows docker container from remote machine (not container host)
  • What is the simplest way to create an EC2 from a docker image hosted on ECR?
  • Docker has two bridge networks named 'bridge'. How to remove?
  • 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": ""

    You can set hostname var at task definition JSON file

    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.