/ aws

Fixing command overrides when running tasks in Amazon ECS

I'm sharing this as there's only a single mention of this in the entire AWS ECS documentation; and no hint in the console UI.

If you attempt to run a one-off task in ECS, for example python manage.py migrate, you might see a cryptic error message like this:

Status reason CannotStartContainerError: API error (404): invalid header field value "oci runtime error: container_linux.go:247: starting container process caused "exec: \"python manage.py migrate\": executable file not found in $PATH"\n"

Command ["python manage.py migrate"]

After searching many unrelated GitHub issues, fiddling with the aws-ecs tool and just attempting to inject likely looking strings into the command field; I eventually stumbled on a single example in the AWS documentation.

For Command override, type the command override to send. If your container definition does not specify an ENTRYPOINT, the format should be a comma-separated list of non-quoted strings.

The trick is to replace spaces (outside of quoted strings) with commas. For example, our earlier command becomes python,manage.py,migrate.

I suspect the reason for this is that in a Dockerfile the format is: CMD ["python", "manage.py", "migrate"]. In fact, this is what the command object (as in the example above) is translated to.

Hope this helped!