How to run AWS ECS Task overriding environment variables

To override environment variables through the CLI, we can use --overrides (structure) according to the AWS ECS Commandline Reference .

How to pass name value pairs (structure or JSON) on the command line?

 [ { "name" : "NAME", "value" : "123" }, { "name" : "DATE", "value" : "1234-12-12" }, { "name" : "SCRIPT", "value" : "123456" } ] 

I am looking for a way to override the above environment variables using the AWS ECS CLI. Sort of:

 aws ecs run-task --overrides <<just environment vars here>> --task-definition ... 

The documentation is not clear. I googled but could not help.

+5
source share
1 answer

You must provide a JSON document as described in --overrides .

 { "containerOverrides": [ { "name": "string", "command": ["string", ...], "environment": [ { "name": "string", "value": "string" } ... ] } ... ], "taskRoleArn": "string" } 

You must specify name for the container in order to get an environment override, and specify a list of environment key-value pairs.

You can specify a JSON document in a string with an argument, or pass an argument to the task path. I will show both ways.

JSON passing in string

Your team will look like this (enter the value CONTAINER_NAME_FROM_TASK ).

 aws ecs run-task --overrides '{ "containerOverrides": [ { "name": "CONTAINER_NAME_FROM_TASK", "environment": [ { "name": "NAME", "value": "123" }, { "name": "DATE", "value": "1234-12-12" }, { "name": "SCRIPT", "value": "123456" } ] } ] }' --task-definition (...) 

It looks pretty ugly, but it would be annoying to edit. It also only works on Unix-y systems and will require code scrolling on Windows.

This way you can transfer the path to the AWS CLI file and load it from JSON from the file.

Passing file path argument

Create a file, call it overrides.json and put the same JSON into it:

 { "containerOverrides": [{ "name": "CONTAINER_NAME_FROM_TASK", "environment": [{ "name": "NAME", "value": "123" }, { "name": "DATE", "value": "1234-12-12" }, { "name": "SCRIPT", "value": "123456" }] }] } 

Then, if your file is in the current directory :

 aws ecs run-task --overrides file://overrides.json --task-definition (..) 

If your file is elsewhere in the file system and you are on a Linux / Unix-y system :

 aws ecs run-task --overrides file:///path/to/overrides.json --task-definition (..) 

If your file is elsewhere in the file system , and you do this on Windows :

 aws ecs run-task --overrides file://DRIVE_LETTER:\path\to\overrides.json --task-definition (..) 
+10
source

Source: https://habr.com/ru/post/1262011/


All Articles