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 réponses
0
Réponse acceptée

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
répondu il y a 2 ans
profile picture
EXPERT
vérifié il y a un mois
0

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

AWS
répondu il y a 2 ans

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions