Skip to content

Cache is missed when building Layer inside a container #3133

@Macok

Description

@Macok

Description:

When a Layer is built using --use-container option and any --container-env-var are passed, the cache is always missed.
This was already fixed by @mndeveci here: #2943, but only for Lambda Functions, while the same problem exists for layers.

Steps to reproduce:

Run below command twice to build any Layer (it will work fine in case of Functions) and see that the cache is not valid.
sam build --cached --use-container --container-env-var FOO=BAR

Observed result:

Cache is missed.

Expected result:

Cache should be hit.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Linux
  2. sam --version: SAM CLI, version 1.27.2
  3. AWS region: N/A

Why does this happen?

Just like in case of #2943, a dictionary of env variables is being passed to the build function by DefaultBuildStrategy.build_single_layer_definition. Additional LAMBDA_BUILDERS_LOG_LEVEL variable is added to the dictionary, causing cache miss. We need to make a deepcopy of this dictionary, just like in DefaultBuildStrategy.build_single_function_definition.

I'm happy to work on a fix as soon as someone confirms my observations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/buildsam build commandcontributors/welcomeContributors are welcome to work on thisstage/acceptedAccepted and will be fixedstage/pr-approvedPR is approved but shouldn't be merged for nowstage/waiting-for-releaseFix has been merged to develop and is waiting for a release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions