Skip to content

ECS task definition image tag

0

Hello,

I have in a task definition something like this: "image": "123565323111.dkr.ecr.eu-central-1.amazonaws.com/image:something",

Each time the service gets restarted, or task stopped and started it comes with a previous image, that not even has a tag on it. I saw that rom the sha that is used inside the task.

Any ideas how I can fix this? Using sha is not a solution for me because each time a new image is uploaded, they force redeploy the service and it should normally use the image with the tag not with sha.

3 Answers
1

If your using CodePipeline, then it will use the sha of the image thats been pushed to the ECR. Ensure your pipeline is correctly setup to launch the right Image and you have no other pipelines in progress. This is normal behaviour and works correctly

EXPERT

answered 2 years ago

0
Accepted Answer

hi Enable FORCE_NEW_DEPLOYMENT when updating the service:

aws ecs update-service --cluster your-cluster --service your-service --force-new-deployment

This forces ECS to pull the latest image.

or

Ensure your CI/CD updates the task definition with a new revision every time a new image is pushed.

EXPERT

answered 2 years ago

0

The behavior you're experiencing is related to how Amazon ECS handles container image resolution and version consistency. When you deploy a container image on a service, ECS resolves the container image tag to a specific image digest (SHA256). This digest becomes the authoritative metadata for that image, ensuring consistency across tasks within a service deployment.

However, this can lead to the situation you're describing, where tasks seem to use an older image even after updates. This happens because ECS caches the resolved digest to maintain consistency within a deployment.

To address this issue and ensure your service uses the latest image when restarted or when tasks are stopped and started, you can try the following approaches:

  1. Force a new deployment: When you update your service, use the "Force new deployment" option. This will cause ECS to resolve the image tag to the latest digest in your ECR repository.

  2. Update your service: After pushing a new image to ECR, update your ECS service. This will trigger a new deployment and resolve the image tag to the latest digest.

  3. Use unique tags: Instead of using a static tag like "something", consider using unique tags for each new image version (e.g., git commit hash, build number). Update your task definition with the new tag each time you deploy.

  4. Implement a CI/CD pipeline: Set up a pipeline that automatically updates your ECS service with the latest image tag whenever a new image is pushed to your ECR repository.

  5. Consider using parameters: In your task definition, you could use a parameter for the image tag. This allows you to specify the exact image tag when you update your stack or service, without changing the task definition itself.

By implementing one or more of these strategies, you can ensure that your ECS tasks are always using the intended container image, even when services are restarted or tasks are stopped and started. This approach provides better control over your deployments and helps maintain consistency between your infrastructure and your application code.

Remember, ECS's behavior of resolving tags to digests is designed to ensure version consistency across your service. By understanding this behavior and implementing appropriate update strategies, you can maintain the flexibility of using tags while ensuring your services use the latest images as intended.

Sources
How are you keeping your CFN template up-to-date with ECS image tags? | AWS re:Post
Use new container image in Amazon ECS | AWS re:Post
Announcing software version consistency for Amazon ECS services | Containers

answered 2 years ago

EXPERT

reviewed 2 years ago

  • Indeed if I just stop task, the new task that gets provision automatically it will come with old value. But it's weird that sometimes even with the "force redeploy" checked it's the same behavior.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.