Skip to content

Instantly share code, notes, and snippets.

@mplewis
Created June 22, 2019 05:27
Show Gist options
  • Save mplewis/f36d179853464beb3c40511000feda6c to your computer and use it in GitHub Desktop.
Save mplewis/f36d179853464beb3c40511000feda6c to your computer and use it in GitHub Desktop.

How to Run a Fargate Task from AWS CLI

AWS_PROFILE=mplewis \
AWS_DEFAULT_REGION=us-west-1 \
aws ecs run-task \
  --launch-type FARGATE \
  --task-definition http-hello-world \
  --network-configuration '<CONFIG>'
  --overrides '<OVERRIDES>'

Network Configuration

  • Required for Fargate because Fargate tasks are required to use awsvpc networking
  • No newlines, remove spaces
  • Pick any subnet
  • Use a security group with full inbound/outbound access, or it'll create an implicit one which may not be able to access Docker Hub. Maybe not best practice, but it's easy
  • Assigning a public IP might help get access to Docker Hub, idk
  • Booleans are ENABLED or DISABLED
awsvpcConfiguration={
  subnets=[subnet-abcd1234],
  securityGroups=[sg-abcd1234abcd12345],
  assignPublicIp=ENABLED
}

Overrides

  • Use this to add env vars on launch
  • Max JSON size is 8192 bytes, so minify this
  • "name" must match the name of the container alias inside your task, e.g. you could alias httpd:2.4 to web-server, so name would be web-server
{
  "containerOverrides": [
    {
      "name": "httpd",
      "environment": [
        { "name": "FOO", "value": "BAR" },
        { "name": "BAZ", "value": "QUUX" },
        {
          "name": "DB_URL",
          "value": "postgres://smeagol:hairball@example.com/catfood"
        }
      ]
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment