Reuse image for functions with same build metadata
See original GitHub issueDescription:
It looks like if you have 2 functions using PackageType: Image
using the same Dockerfile, sam build
does not correctly add ImageUri
to all functions.
I have traced through the code that all functions are added to the same build_definition
but the build results are not copied to all functions. There is an explicit if condition to only do this to ZIP
, is there a reason for this or it’s just a feature not supported yet?
Steps to reproduce:
Example template:
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Parameters:
Tag:
Type: String
Default: latest
Description: Docker tag to build and deploy.
Globals:
Function:
Timeout: 5
Resources:
FooFunction:
Type: AWS::Serverless::Function
Properties:
PackageType: Image
ImageConfig:
Command:
- foo
Metadata:
DockerTag: !Ref Tag
DockerContext: .
BarFunction:
Type: AWS::Serverless::Function
Properties:
PackageType: Image
ImageConfig:
Command:
- bar
Metadata:
DockerTag: !Ref Tag
DockerContext: .
Observed result:
The “built” template only has ImageUri
on the BarFunction:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
Tag:
Type: String
Default: latest
Description: Docker tag to build and deploy.
Globals:
Function:
Timeout: 5
Resources:
BarFunction:
Type: AWS::Serverless::Function
Properties:
PackageType: Image
ImageConfig:
Command:
- bar
ImageUri: barfunction:latest
Metadata:
DockerTag:
Ref: Tag
DockerContext: .
FooFunction:
Type: AWS::Serverless::Function
Properties:
PackageType: Image
ImageConfig:
Command:
- foo
Metadata:
DockerTag:
Ref: Tag
DockerContext: .
Expected result:
Expect to re-use the same image for multiple functions.
I can however see an issue because the image name includes the first function name.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: mac
sam --version
: 1.13.2
Issue Analytics
- State:
- Created 3 years ago
- Reactions:12
- Comments:14 (3 by maintainers)
Top Results From Across the Web
sam build - AWS Serverless Application Model
Build an AWS SAM application using the sam build command from the AWS SAM CLI. ... function resources that have the Image package...
Read more >Multi-stage builds - Docker Documentation
Use multi-stage builds🔗 ... With multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base,...
Read more >Best practices for speeding up builds - Google Cloud
Kaniko cache is a Cloud Build feature that caches container build artifacts by storing and indexing intermediate layers within a container image registry,...
Read more >Chapter 4. Creating images OpenShift Container Platform 4.9
Doing so ensures the next builds of the same image are very fast because the ... Defining image metadata helps OpenShift Container Platform...
Read more >Presenting Images - Sanity.io
The image references an asset which represents the actual image data to be displayed for this image. (One asset may actually be shared...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Commenting for support, I would also like to be able to reuse the same image for multiple lambdas.
FYI, I found another bug, though I believe this one is much deeper than SAM (or at least the part that runs locally). It appears that if you specify a Command in the template it will lose track of the EntryPoint. I found that I had to specify both Command and Entrypoint (‘/lambda-entrypoint.sh’) in order to be able to successfully override the command. If you run into issues about missing entry points then give that a shot.