how to provide environment variables to AWS ECS service?

Viewed 3227

Trying to create a service in ECS and unbelievably looks like it is not possible to specify any environmental variables...

Is it possible to do that without updating my task definition and recreate the service? Or a task override option?

This looks a bit cumbersome

2 Answers

The environmental variables are provided through task definition. Thus you have to update the definition to add/change the variables.

You don't have to re-create the service from scratch. You can update your service to use the new version of your task definition. For updating existing service you can use update-service AWS CLI call. The cli also provides --force-new-deployment if you want to force the deployment (but changing task should be enough and forcing would not be required).

You can't define environment variables at service creation time as explained by the other answer but you can define tags: thus one workaround is to

  1. Create a service with a set of tags and propagateTags: SERVICE
  2. On container startup read the cluster and task ARNs from the task metadata endpoint
  3. Read service tags with the DescribeTasks API (note the include: ['TAGS'] parameter)
  4. Configure the environment using the tag values
Related