Your CodePipeline ECS deployment is failing with a The AWS ECS container ${container} does not exist
message.
This problem can occur in a number of situations but let’s just imagine we have a task definition contains a single entry in its container definitions
.1 Now we want to add another container to the task, say a sidecar container like the datadog agent.
First, you add it to your ECS task definition and push a new revision.
[
...
...
{
"name": "${datadog_name}",
"image": "${datadog_image}",
"essential": true,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/aws/ecs/${cluster_name}/${datadog_name}",
"awslogs-region": "us-west-2",
"awslogs-stream-prefix": "${datadog_name}"
}
},
"secrets": [
{ "name": "DD_API_KEY", "valueFrom": "${DD_API_KEY}" }
],
"environment": [
{ "name": "ECS_FARGATE", "value": "true" }
]
}
]
Second, you add it to your imagedefinitions.json
generated in your CodePipeline build stage.
[
{
"name": "${your_container_name}",
"imageUri":"${your_container_image}"
}
{
"name": "${datadog_agent_name}",
"imageUri":"${datadog_agent_image}"
}
]
After that, you run a new CodePipeline and run into the following error: The AWS ECS container datadog-agent does not exist
.
What the heck?
The ECS service being updated with a new task definition from CodePipeline MUST have the container defined in it. This means that you must add the container definition, create a new task revision, AND force a new service deployment prior to doing an ECS deployment via CodePipeline.