CodeBuild: sam package computes a different MD5 hash for unchanged lambda source code
See original GitHub issueDescription:
Setup i am having:
- a lambda function written in
node.js
- sam template for that lambda
buildspec
that is runningsam build
andsam package
- everything is deployed via
CodePipeline
and is usingCodeBuild
- code is deployed to
github
sam package
that is running on theCodeBuild
instance is computing a newMD5
hash for the lambda source code in spite of lambda function being changed or not- i believe it has to do with the fact that
CodeBuild
environment is ephemeral, and the way we are calculatingmd5
hash here.
Code snippet:
@contextmanager
def zip_folder(folder_path):
"""
Zip the entire folder and return a file to the zip. Use this inside
a "with" statement to cleanup the zipfile after it is used.
Parameters
----------
folder_path : str
The path of the folder to zip
Yields
------
zipfile_name : str
Name of the zipfile
md5hash : str
The md5 hash of the directory
"""
md5hash = dir_checksum(folder_path, followlinks=True)
filename = os.path.join(tempfile.gettempdir(), "data-" + md5hash)
zipfile_name = make_zip(filename, folder_path)
try:
yield zipfile_name, md5hash
finally:
if os.path.exists(zipfile_name):
os.remove(zipfile_name)
Steps to reproduce:
- Create a simple lambda with sam
- create a
buildspec
that will runsam build
+sam package
- Create
CodePipeline
withCodeBuild
step - Go to
CodePipeline
and runRelease Change
multiple time (essentially you are building the same revision)
Observed result:
- lambda is being redeployed each time you run
release change
in code pipeline
Expected result:
- this should not result in lambda being redeployed every time you run
release change
, since there were no code changes made
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
I will create a sample repo with the code shortly
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:12 (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.
Read more >Tag Archives: F1 - Noise
AWS CodeBuild is a fully managed build service that compiles source code, runs tests, and produces software packages that are ready to deploy....
Read more >Building a CI/CD pipeline for an AWS Lambda function using ...
A guide on building a CI/CD pipeline for a serverless Java application using AWS Lambda, AWS Serverless Application Model (AWS SAM), ...
Read more >NEWS.txt - FTP Directory Listing
If you are using a package with both the Apple system Python 2.7 and a user-installed ... The pgen output is normally saved...
Read more >DEEP DIVE INTO AWS SAM BUILDING AND PACKAGING ...
We also get into the details of how Eric is building AWS Lambda ... Other videos you might be interested in: - Repo...
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
@mndeveci - The issue can be reproduced as follows in Code Pipeline:
Source stage - Github repo
Build stage:
sam build
sam package --output-template-file packaged.yaml --s3-bucket <S3 bucket>
Deploy stage: CloudFormationCreateUpdateStackAction
@mndeveci How are you deploying the stack in local env or via code pipeline? If you deploy via local then it works well but when you use code pipeline with code build and code deploy then the complete stack is redeploying without any modification. so the problem is md5 varies when deploying stack from the new environment.