Use externally built docker image in multiple functions
See original GitHub issueDescription:
I would like to deploy a stack with multiple functions that use the same docker image that I build manually beforehand (not with sam build, so I did not set the template Metadata
). I was basically following the example here.
Each function has a custom command, while entrypoint and working dir are the same (explicitly set due to other bugs I read about). Pseudo example:
FunctionOne:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub "function-one-${Env}"
PackageType: Image
ImageUri: !Sub ${Account}.dkr.ecr.${Region}.amazonaws.com/repo-name:${Tag}
ImageConfig:
Command: ["main.function_one"]
EntryPoint: ["/lambda-entrypoint.sh"]
WorkingDirectory: "/var/task/"
FunctionTwo:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub "function-two-${Env}"
PackageType: Image
ImageUri: !Sub ${Account}.dkr.ecr.${Region}.amazonaws.com/repo-name:${Tag}
ImageConfig:
Command: ["main.function_two"]
EntryPoint: ["/lambda-entrypoint.sh"]
WorkingDirectory: "/var/task/"
I skip sam build
and sam package
since the artifact is already pushed to the specified ECR repository.
When I run sam deploy
(passing also the necessary override parameters), after the changeset gets created, the cloudformation events output contains the following for each function of the stack, and then it rollbacks the deploy:
Please don't provide ImageConfig when the intended function PackageType is Zip.
(Service: AWSLambdaInternal; Status Code: 400; Error Code: InvalidParameterValueException; Request ID: f7293f26-122c-4295-9332-ccaac8cede70; Proxy: null)
I tried specifying --image-repository
to the same ecr repo in the template, and again duplicating it for each function resource in image_repositories
in the samconfig.toml
image_repositories = [
"FunctionOne=123456.dkr.ecr.eu-west-1.amazonaws.com/repo-name",
"FunctionTwo=123456.dkr.ecr.eu-west-1.amazonaws.com/repo-name",
]
Observed result:
During the deploy, with --debug
set, amongst the output I see
Property ImageUri of FunctionOne resource is not a URL or a local image … Unable to resolve property Endpoint: OrderedDict([(‘Fn::GetAtt’, [‘FunctionOne’, ‘Arn’])]). Leaving as is. … Found Serverless function with name=‘FunctionOne’ and ImageUri=‘123456.dkr.ecr.eu-west-1.amazonaws.com/repo-name:test’
Changeset created successfully. arn:… Waiting for stack create/update to complete CloudFormation events from changeset
ResourceStatus | ResourceType | LogicalResourceId | ResourceStatusReason |
---|---|---|---|
UPDATE_IN_PROGRESS | AWS::Lambda::Function | FunctionOne | - |
UPDATE_FAILED | AWS::Lambda::Function | FunctionOne | Please don’t provide ImageConfig when the intended function PackageType is Zip. |
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: MacOS
sam --version
: SAM CLI, version 1.18.1- AWS region: eu-west-1
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Roughly the same issue here, but using Azure
CloudFormationCreateOrUpdateStack
rather thansam deploy
(those might do the same thing down the line - not sure).Edit: solved by deleting the old cloudformation stack, which had the lambdas still built from zips. Apparently the PackageType property cannot be updated.
Just ran into this. Would be nice to have a better error message as I was utterly confused (same case: migrating from a ZIP package to an image package).