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 年前1581 查看次数
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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则