Answers: <p>You can use DockerImageAsset to initialize ECR with a base image like scratch or alpine, or even the most basic lambda container that would get your lambda function to execute.</p>
  <p><a href="https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr_assets.DockerImageAsset.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr_assets.DockerImageAsset.html</a></p>
  <p><a href="https://hub.docker.com/_/scratch" rel="nofollow noreferrer">https://hub.docker.com/_/scratch</a></p>
  <p>Later, when you get the github actions going you just replace the image</p>
  
Answers: CC BY-SA 4.0
Answers: 2022-01-08T03:57:26.153Z
Answers: 2022-01-08T03:57:26.153Z
Answers: Magus
Body: <p>In CDK, if I have something like this:</p>
  <pre><code>const repository = new ecr.Repository(this, 'SomeRepository', {
    repositoryName: 'SomeRepository',
  });
  
  const lambda = new lambda.DockerImageFunction(this, 'SomeLambda, {
    code: lambda.DockerImageCode.fromEcr(repository, { tag: 'latest' },
    functionName: 'SomeLambda',
    vpc: this.vpc,
    vpcSubnets: this.vpcSubnets,
  });
  </code></pre>
  <p>CDK will fail to deploy, because there is no image present in the ECR that was just barely created. The idea is to set everything up, and then setup github actions to upload the image, and tell the lambda where to get the code.</p>
  <p>How can I get everything set up so that it is ready for CD like this?</p>
  
Tags: <amazon-web-services><aws-cloudformation>
Title: CDK: How to solve chicken and egg problem of Lambda backed with ECR
UserDisplayName: synic
ThreadText: # CDK: How to solve chicken and egg problem of Lambda backed with ECR
  
  (Asked by: username_0 on 2022-01-07)
  
  In CDK, if I have something like this:
  
  ```
  const repository = new ecr.Repository(this, 'SomeRepository', {
    repositoryName: 'SomeRepository',
  });
  
  const lambda = new lambda.DockerImageFunction(this, 'SomeLambda, {
    code: lambda.DockerImageCode.fromEcr(repository, { tag: 'latest' },
    functionName: 'SomeLambda',
    vpc: this.vpc,
    vpcSubnets: this.vpcSubnets,
  });
  
  ```
  
  CDK will fail to deploy, because there is no image present in the ECR that was just barely created. The idea is to set everything up, and then setup github actions to upload the image, and tell the lambda where to get the code.
  
  How can I get everything set up so that it is ready for CD like this?
  
  **Tags:** amazon-web-services, aws-cloudformation
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-01-08. Score: 1 | Accepted answer
  
  You can use DockerImageAsset to initialize ECR with a base image like scratch or alpine, or even the most basic lambda container that would get your lambda function to execute.
  
  <https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr_assets.DockerImageAsset.html>
  
  <https://hub.docker.com/_/scratch>
  
  Later, when you get the github actions going you just replace the image
  
  
  ---
  
  