Goal: Use the aws cli in a subprocess.run call to execute a command in a container of a running task.
Example Usage:
task_arn = 'a_task_arn'arg = event = {'something': 'that contains ( )'}# Attempt 1: json stringarg = json.dumps(arg)subprocess_cmd = 'aws ecs execute-command --command "python -m task.function {arg}" --interactive --task {task_arn} --container Container'subprocess.run(subprocess_cmd, shell=True# Attempt 2: encoded json stringarg = json.dumps(arg).encode('utf-8')subprocess_cmd = 'aws ecs execute-command --command "python -m task.function {arg}" --interactive --task {task_arn} --container Container'subprocess.run(subprocess_cmd, shell=TrueEncountered Error: /bin/sh: 1: Syntax error: "(" unexpected
I am trying to use the cli through a subprocess.run call instead of using the boto3 execute_command because
- it doesn't appear that there is an easy way to read the websocket boto3 returns: https://github.com/boto/boto3/issues/3496,
- as indicated in this SO answer, it only returns a very small portion of the websocket message: How can I get output from boto3 ecs execute_command?