Search code examples
pythonamazon-ecs

running python script with an ECS task


I have an ECS task setup which, when with a Command override ls, produces expected results with my CloudWatch log stream: test.py. my script test.py takes one parameter. I am wondering how I can execute this script with python3 (which exists in my container) using the command override. Essentially, I want to execute the command:

 python3 test.py hello

how can I do this?


Solution

  • Here's how I did something similar:

    In your docker build file, make the command you want to run as the last instruction. In your case:

    CMD python3 test.py hello
    

    To make it more extensible, use environment variables. For instance, do something like:

    CMD ["python3", "test.py"]
    

    But make the parameter come from an environment variable you pass into the container definition in your task.