Closed davidjb closed 9 months ago
Thanks for reporting this issue.
As you mentioned, it is happening inside the resource metadata normalizer. But it is also related the way that you reference some values in the template. The python representation of your template also references those values, so changing one of the metadata actually applying that change to all the others. For that reason, all resources' metadata got updated if one of them changed.
I will be labeling this as bug and talking with the team for next steps.
Patch is released in v1.98.0. Closing
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