SAM to deploy Image-Based Lambda

0

My Question: Can you create an ECR repository and an Image-backed lambda from a Dockerfile from my local via SAM without the need to build the image and upload it first outside of SAM? I was hoping I could define my Dockerfile, the relative file paths, and SAM would handle the rest.

Context: I want to use SAM to manage an ECR repository and the Docker image that will back a lambda function. I have attempted a combination of configurations in the SAM template including:

  • defining the ECR repository
  • using the Metadata to point to the Dockerfile that sits alongside the Lambda function (python)
  • Specifying the ImageURI
  • Specifying CodeURI

The error appears to be related to the fact that the image is not being added to ECR. Naturally, SAM rolls back the deploy, so I am trying to figure out where things are falling over.

1 Answer
3

Yes, you can create an ECR repository and deploy an image-backed Lambda function directly from a Dockerfile without manually building and uploading the image outside of SAM, below the sample about SAM template of Dockerfile base on Yaml:

Resources:
  MyLambdaFunction:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      ImageConfig:
        Command: ["app.lambda_handler"]
      MemorySize: 512
      Timeout: 10
    Metadata:
      Dockerfile: Dockerfile
      DockerContext: ./path-to-docker-context
      DockerTag: latest
EXPERT
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions