Skip to content

"lambda deploy-serverless" command tries to build image when ImageUri is set without any Metadata #264

@roncrush

Description

@roncrush

Describe the bug

According to the docs for "AWS::Serverless::Function" the "ImageUri" property can be set if the image has already been pushed to somewhere like ECR (https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html#sam-function-imageuri).

The behavior I'm seeing with the command "lambda deploy-serverless" is that it treats the "ImageUri" like a local path as if it's trying to build the image and push it.

Expected Behavior

The command should result in the function being successfully deployed by the CloudFormation stack.

Current Behavior

The following error appears:

Processing CloudFormation resource <Function Name>
Initiate packaging of <ImageUri> for resource
Directory that the field <Function Name>/CodeUri-Or-ImageUri is pointing doesn't exist

Reproduction Steps

  1. Initialize the hello world sample:
sam init --package-type Image --base-image amazon/dotnet6-base
  1. Manually build and deploy the Dockerfile to somewhere like ECR.
  2. Update the template.yaml file to look like this (replace the <ImageUri> with the deployed image URI):
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Template to test bug with ImageUri

Globals:
  Function:
    Timeout: 10
    MemorySize: 128

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      ImageUri: <ImageUri>

4, Run the "dotnet lambda deploy-serverless" command (will need a S3 bucket):

dotnet lambda deploy-serverless --s3-bucket "some-bucket-for-testing-bug" --s3-prefix "bug/" --stack-name "test-bug" --template "template.yaml"

Possible Solution

It seems like the packaging step should be skipped for Lambda Functions that have an ImageUri set without any metadata.

Additional Information/Context

No response

Targeted .NET platform

6.0.302

CLI extension version

Package Id Version Commands
amazon.lambda.tools 5.6.3 dotnet-lambda
dotnet-ef 6.0.8 dotnet-ef

Environment details (OS name and version, etc.)

macOS Monterey Version 12.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions