Fixing AWS ECS execute-command TargetNotConnectedException when using Fargate
In the past week I've encountered an error when trying to run aws ecs execute-command
on
a Fargate container running platform 1.4.0.
This worked fine on containers created over a week ago but recent ones failed with:
An error occurred (TargetNotConnectedException) when calling the ExecuteCommand operation: The execute command failed due to an internal error. Try again later
Turns out there must be some sort of silent update, thankfully a helpful person [1] encountered the same thing back in November (no idea why it had worked fine for me until now).
Turns out if you have AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
as environment variables in the
task definition and these credentials don't have the permissions required for execute-command
then the command fails in this mysterious way.
[1] GitHub