0

I have an ECS task running a docker container that initially started with an task override. The override contains an environment variable. Now I want to update the environment variable while having the task running, how should I do this? Thank you.

  • 1
    Even if AWS somehow allows you to change the variable on the task, there isn't a way to change it on a running process, so it's not going to affect whatever you have running in the task container. – jingx Apr 24 '21 at 03:29
  • @jingx Thank you so much for your comment. So the only way for me to update the variable is to stop and current task and start a new one? What I am trying to do is to reduce the latency of starting the task (which takes about 1-2 min). I was thinking to have a task run first, and when the request comes it can serve immediately without letting users wait for the start time. But if I can't update a running task then I guess it's no feasible to do that, am I right? – redqles Apr 24 '21 at 04:30
  • You can still achieve that, just not with an environment variable. Can you put the parameters somewhere - S3, parameter store, or a volume mounted by the container? – jingx Apr 24 '21 at 04:35
  • You can use [ecs exec](https://aws.amazon.com/about-aws/whats-new/2021/03/amazon-ecs-now-allows-you-to-execute-commands-in-a-container-running-on-amazon-ec2-or-aws-fargate/) to run command in the container and update it. But as others said, you can just do it by modifying env variables. – Marcin Apr 24 '21 at 07:37
  • @jingx Could you explain more about how I could do that via storing the parameters in S3 for example? Thanks! – redqles Apr 25 '21 at 04:03
  • @Marcin, thanks a lot for your comment. Does it mean that I can run a command like export ENV_VARIABLE = XXX using ecs exec to update the environment variable in the container? – redqles Apr 25 '21 at 04:43
  • It depends how your program runs. Does it iteratively check check of changes in env variables? Does it run in its own shell? Its difficult to speculate, but you can test it out. – Marcin Apr 25 '21 at 04:46

0 Answers0