- Newest
- Most votes
- Most comments
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
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.
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:
-
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.
-
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.
-
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.
-
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.
-
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
Relevant content
asked 4 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.