Bug: Using YAML anchors for Resource Metadata makes resource disappear due to template mutation #5901
Labels
area/build
sam build command
stage/waiting-for-release
Fix has been merged to develop and is waiting for a release
type/bug
Description:
I have a large number of Go Lambda functions defined in my
template.yaml
and I was looking to simply my SAM template and make it more DRY by using anchors on theirMetadata
property like so:However, when doing this, the given function becomes no longer available to SAM (see below).
The reasoning because SAM adds the
SamResourceId
key within a resource's metadata (https://github.com/aws/aws-sam-cli/blob/develop/samcli/lib/samlib/resource_metadata_normalizer.py#L95-L99) and this gets used to create a list of available resources to build (https://github.com/aws/aws-sam-cli/blob/develop/samcli/commands/build/build_context.py#L565-L568). The problem occurs because the underlyingOrderedDict
structure is shared between functions, then the shared object gets mutated by the the normalizer when setting its properties.This same issue can/will occur anywhere else the template structure where the template is being mutated so prior making changes, the original data structure should be copied.
Steps to reproduce:
template.yaml
like so:sam build SecondFunction --debug
Observed result:
Expected result:
All functions to be available and buildable.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
Add --debug flag to command you are running
The text was updated successfully, but these errors were encountered: