Skip to content

fix Globals.Function Architectures override behavior#3940

Open
allenheltondev wants to merge 1 commit into
aws:developfrom
allenheltondev:issue-3939_function_architectures_bug
Open

fix Globals.Function Architectures override behavior#3940
allenheltondev wants to merge 1 commit into
aws:developfrom
allenheltondev:issue-3939_function_architectures_bug

Conversation

@allenheltondev

Copy link
Copy Markdown

Issue #, if available

Fixes #3939

Description of changes

Updates Globals.Function merge behavior so resource-level Architectures overrides global Architectures instead of concatenating both lists.

Architectures is list-shaped, but Lambda functions support a single architecture value. This keeps the existing default list merge behavior for other properties, such as Layers, while handling Architectures like other overridable function properties.

Description of how you validated changes

Ran:

python -m pytest tests/plugins/globals/test_globals.py --no-cov

Result: 48 passed.

Also updated the globals_for_function translator fixture to cover resource-level Architectures overriding Globals.Function.Architectures across standard, aws-cn, and aws-us-gov outputs.

Integration tests were not added because this change is limited to Globals merge behavior and is covered by unit tests plus translator output fixtures.

Checklist

Examples?

Please reach out in the comments if you want to add an example. Examples will be
added to sam init through aws/aws-sam-cli-app-templates.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Signed-off-by: Allen Helton <allenheltondev@gmail.com>
@allenheltondev allenheltondev requested a review from a team as a code owner June 11, 2026 11:41

@reedham-aws reedham-aws left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for raising this!

Seems like the linter is failing as well, you can fix locally with make format or make lint.

Comment on lines +457 to +468
global_properties = self._drop_overridden_globals(self.global_properties, local_properties)
return self._do_merge(global_properties, local_properties) # type: ignore[no-untyped-call]

def _drop_overridden_globals(self, global_properties, local_properties): # type: ignore[no-untyped-def]
if not self.override_properties or not isinstance(global_properties, dict) or not isinstance(local_properties, dict):
return global_properties

global_properties = global_properties.copy()
for key in self.override_properties:
if key in global_properties and key in local_properties:
del global_properties[key]
return global_properties

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this approach makes sense and would work, but I my first instinct is that we could get rid of the loop/copy by checking the override_properties in _merge_dict. I left another comment in the place where that might work, but I could be missing something, let me know what you think.

global_dict = global_dict.copy()

for key in local_dict:
if key in global_dict:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could have a condition here to see if the key is in the overrides, and if it's not then we could enter the else. I think this would accomplish the same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Globals.Function Architectures should be overridden by resource-level Architectures

2 participants