How to create an container image and deploy it to an lambda function using CDK?

0

I want to create a CDK stack that can make an container image and deploy it to an lambda function. I have just built a stack which contain a codebuild project that build an image, and push it to an ECR repo, but have no clue how to do the deployment to an lambda.

Based on the cdk API ref, it seems like the codepipeline module could do the job, but I can't find the way to deploy a lambda with container image. What cdk modules else I need to do the deployment?

And also, in a cdk app, how to handle one stack is depending on another stack's long-running task, like the task I just mentioned that a lambda function made by a container image, which made by a codebuild project and stored in an ECR repo?

Thanks!

2回答
0
承認された回答

Use aws-ecr-assets cdk module

import { DockerImageAsset } from '@aws-cdk/aws-ecr-assets';
const asset = new DockerImageAsset(this, 'MyBuildImage', {
  directory: path.join(__dirname, 'my-image'),
  buildArgs: {
    HTTP_PROXY: 'http://10.20.30.2:1234',
  },
  invalidation: {
    buildArgs: false,
  },
});

The directory my-image must include a Dockerfile.

This will instruct the toolkit to build a Docker image from my-image, push it to an Amazon ECR repository and wire the name of the repository as CloudFormation parameters to your stack.

AWS
回答済み 2年前
profile picture
エキスパート
レビュー済み 1ヶ月前
0

I think you should use Multi-stage image builds for this use case.

AWS
回答済み 2年前

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

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

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

関連するコンテンツ