Deploy updated container to existing CDK stack

1

I have a Fargate service deployed with ecs_patterns.ApplicationLoadBalancedFargateService and I'd like it to roll out a new container that has been pushed to the ECR repo used for this service.

I have a pipeline producing the new container for the service but if I run cdk synth and then deploy after, CDK does not detect a change when it generates the CloudFormation changeset as the container tag does not change (latest). I updated it so the build pushes a unique container tag to SecretsManager and resolves this during deploy but this also doesn't work as the reference to the tag isn't picked up during changeset creation (would only pull the tag when deploying).

What's the best way to get CDK to deploy a new version of the container? Pass tag in dynamically or should I just go with CodeDeploy?

AWS
Tom_E
質問済み 4年前2119ビュー
1回答
0
承認された回答

I would find a way to reference the same image tag in your cdk app that you use in your image build/tag/push stage.

For example, if you had a docker stage that pushed an image using the environment variable CODEBUILD_RESOLVED_SOURCE_VERSION as the tag like:

docker build -t $IMAGE_REPO_NAME:$CODEBUILD_RESOLVED_SOURCE_VERSION .
docker push $IMAGE_REPO_NAME:$CODEBUILD_RESOLVED_SOURCE_VERSION

You could then reference that tag in your CDK app:

const tag = process.env.CODEBUILD_RESOLVED_SOURCE_VERSION;
const image = ecs.ContainerImage.fromEcrRepository(ecrRepo, tag);

new ApplicationLoadBalancedFargateService(this, 'Service', {
  taskImageOptions: {
    image: image,
    ...
  },
  ...
});
AWS
回答済み 4年前
profile picture
エキスパート
レビュー済み 1ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ