aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

sam local invoke with pre-built image

Open hikouki-gumo opened this issue 8 months ago • 1 comments

Description

My function uses dependencies from a private Github repository and I have to --mount feature of BuildKit to build Docker image, but SAM does not support BuildKit. Then I have to build image separately first and then define that pre-built image in field ImageUri of template.yaml.

Issue happens when I test on local, SAM must build on fly image to run function -> It can not build image, then can not invoke local.

Is there any way to invoke sam local for this use case? Or SAM does not support that?

AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31

Resources:
  FormDataExtractionFunction:
    # No MetaData definition
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: "my-lambda-function"
      PackageType: Image
      ImageUri: "library/test-lambda:latest" # Specify local image

...

hikouki-gumo avatar Apr 18 '25 03:04 hikouki-gumo

Not 100% sure, but try editing the AWS::Serverless::Function resource in your template.yaml:

Remove

Metadata:
  Dockerfile: Dockerfile
  DockerContext: ./functions/<somefunc>

Set you local prebuilt image to

ImageUri: myimage:latest

**update Sadly you won't be able to run and debug it using vscode/pycharm aws toolkit, without the metadata section.

royassis avatar Apr 27 '25 12:04 royassis

Do you mind providing a sample image function any step to reproduce?

vicheey avatar Jun 23 '25 06:06 vicheey