question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CodeBuild: sam package computes a different MD5 hash for unchanged lambda source code

See original GitHub issue

Description:

Setup i am having:

  • a lambda function written in node.js
  • sam template for that lambda
  • buildspec that is running sam build and sam package
  • everything is deployed via CodePipeline and is using CodeBuild
  • code is deployed to github
  • sam package that is running on the CodeBuild instance is computing a new MD5 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 calculating md5 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 run sam build + sam package
  • Create CodePipeline with CodeBuild step
  • Go to CodePipeline and run Release 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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
vijay2krcommented, Jun 17, 2021

@mndeveci - The issue can be reproduced as follows in Code Pipeline:

  1. Source stage - Github repo

  2. Build stage: sam build sam package --output-template-file packaged.yaml --s3-bucket <S3 bucket>

  3. Deploy stage: CloudFormationCreateUpdateStackAction

1reaction
Karthi96commented, Jun 17, 2021

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found