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 Respuestas
0
Respuesta aceptada

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
respondido hace 2 años
profile picture
EXPERTO
revisado hace un mes
0

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

AWS
respondido hace 2 años

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas