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 Risposte
0
Risposta accettata

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
con risposta 2 anni fa
profile picture
ESPERTO
verificato un mese fa
0

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

AWS
con risposta 2 anni fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande