Skip to content

Conversation

@vicheey
Copy link
Contributor

@vicheey vicheey commented Dec 4, 2025

Which issue(s) does this change fix?

#8148

Why is this change necessary?

When running sam sync with functions that have the Layers property defined as a CloudFormation intrinsic function (e.g., Fn::If, Ref, Fn::GetAtt), the command crashes with AttributeError: 'collections.OrderedDict' object has no attribute 'append'. This prevents users from deploying stacks that use conditional or dynamic layer configurations.

How does it address the issue?

The auto-dependency layer creation logic in nested_stack_manager.py attempted to call .append() on the Layers property without checking if it was an intrinsic function (which is represented as an OrderedDict/dict, not a list).

Resolution:

  1. Added is_intrinsic_function() utility in samcli/lib/utils/cloudformation.py to detect all CloudFormation intrinsic functions
  2. Modified nested_stack_manager._add_layer() to check for intrinsic functions before attempting to create or append auto-dependency layers
  3. When an intrinsic function is detected, the function logs a warning and skips auto-dependency layer creation for that function, preserving the user's intrinsic function unchanged
  4. The original template with intrinsic functions is deployed to CloudFormation where they are resolved at deployment time

Key Changes:

  • samcli/lib/utils/cloudformation.py: Added is_intrinsic_function() helper
  • samcli/lib/bootstrap/nested_stack/nested_stack_manager.py: Added early return when Layers is an intrinsic function
  • samcli/lib/providers/sam_function_provider.py: Added intrinsic function check in _parse_layer_info() (already existed, enhanced with shared utility)
  • Add test coverage for all intrinsic function types

What side effects does this change have?

  • Functions with intrinsic function Layers will not receive auto-dependency layers (by design as it is existing broken experience - cannot append to dynamic/conditional configurations)
  • A warning message is logged when this occurs to inform users
  • The user's original intrinsic function configuration is preserved and deployed to CloudFormation unchanged
  • No impact on functions with regular list-based Layers properties

Mandatory Checklist

PRs will only be reviewed after checklist is complete

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

@vicheey vicheey marked this pull request as ready for review December 5, 2025 21:49
@vicheey vicheey requested a review from a team as a code owner December 5, 2025 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant