CDK deployments with dynamic ecs task definitions

0

I'm deploying an ECS Cluster and Service with a Task Definition with the CDK. For organizational reasons, I run a build process with Github Actions that creates new versions of containers and then deploys them by creating new versions of the task definition that get deployed to the service I created with CDK.

I noticed that when I make changes to the service with CDK (not the task definition) it will roll back to the previous version of the task definition rather than the latest version of the definition that I deployed externally. I would rather not have deployed the task definition with CDK (I thought this might be an issue) - but it seems to be required to deploy the service with CDK.

If I never make changes to the service in CDK, everything is fine. But if I do, it'll roll back my task definition. How can I avoid this? Better yet, am I missing a best practice here/asking the wrong question?

  • Hi, I would suggest to update your question with the ECS-relevant part of your CDK code. That would help to understand how you ask ECS to choose the container image.

  • Hi! I suspect this would actually not help much - my CDK based task definition has a "dummy" container image. It just deploys a vanilla image of nginx. When the github action runs, it creates a brand new task definition that pulls from an ECR repo. This is why my cdk service updates are a problem - it reverts to the dummy nginx image.

已提問 4 個月前檢視次數 436 次
1 個回答
1
已接受的答案

Hi,

Your ECS task definition (see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.TaskDefinition.html) points to a container image.

If you update your image, you must update the task definition in CDK so that it takes the latest image.

AWS recommendation is to not use 'latest' as image tag but commit id.

So, you CDK project should make use of an env var defining the commit id to use for the image tag included in the task definition

Best

Didier

profile pictureAWS
專家
已回答 4 個月前
profile picture
專家
已審閱 8 天前
profile picture
專家
已審閱 1 個月前
  • This is fair (and I've avoided using 'latest' for just this reason), but I've avoided this because that would mean I'd need to deploy from specific machines or environments. Not just anyone could run cdk deploy on their machine. In the past I've tried dynamic aws api calls within CDK to grab dynamic bits of configuration (like the most recent task definition, for instance), but this has traditionally caused problems/frustration.

  • Thnak you for the feedback and acceptation of answer

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南