Skip to content

Conversation

@arthurboghossian
Copy link
Contributor

Issue #, if available: #8075

Description of changes:

Allow "aws cloudformation package" to succeed when a Resource is not a key-value pair.

This includes supporting the new Fn::ForEach intrinsic function, which can be provided as a key-value pair within the Resources section, where the value is not a key-value pair, as expected, but a list.

Note: was able to successfully run aws cloudformation package and aws cloudformation deploy on CloudFormation templates that contained the Fn::ForEach intrinsic function.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@arthurboghossian
Copy link
Contributor Author

Added a warning message that local artifacts aren't currently supported in Resources that aren't defined as key-value pairs

…ic function by recursively calling the export function on the fragment property of Fn::ForEach
@arthurboghossian
Copy link
Contributor Author

In the latest commit, modified artifact_explorer, where instead of skipping over resources that aren't dictionaries, modifying the export method to be able to handle the Fn::ForEach intrinsic function by recursively calling the export function on the fragment property of Fn::ForEach

@codecov-commenter
Copy link

codecov-commenter commented Sep 27, 2023

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (42cdbca) 0.08% compared to head (7e7b8c2) 0.08%.

Files Patch % Lines
...customizations/cloudformation/artifact_exporter.py 0.00% 9 Missing ⚠️
awscli/customizations/cloudformation/exceptions.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           develop   #8096      +/-   ##
==========================================
- Coverage     0.08%   0.08%   -0.01%     
==========================================
  Files          208     208              
  Lines        16673   16682       +9     
==========================================
  Hits            14      14              
- Misses       16659   16668       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@kyleknap kyleknap left a comment

Choose a reason for hiding this comment

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

Looks good. I just had some smaller comments.

continue

resource_type = resource.get("Type", None)
if resource_type is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a particular reason this if check was added for the Type? A sample CFN template snippet would help illustrate what it is addressing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had added this (removed it from the latest commit) to prevent the need to go through the items in self.resources_to_export if the resource_type resolves to None (see loop below)

            resource_type = resource.get("Type", None)
            # ...
            for exporter_class in self.resources_to_export:
                if exporter_class.RESOURCE_TYPE != resource_type:
                    continue
                # ...

However, looking at the Resource class, if RESOURCE_TYPE is not defined for a subclass of a Resource, it would also resolve to None, thought I don't think we'd every have such a subclass, but it is possible, so opting to not have this change as part of this PR

Copy link
Contributor

@hssyoo hssyoo left a comment

Choose a reason for hiding this comment

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

🚀

@hssyoo hssyoo merged commit 2676a46 into aws:develop Dec 14, 2023
aws-sdk-python-automation added a commit that referenced this pull request Dec 15, 2023
* release-1.32.2:
  Bumping version to 1.32.2
  Update changelog based on model updates
  Support Fn::ForEach intrinsic function (#8096)
AvnerCohen pushed a commit to hiredscorelabs/aws-cli that referenced this pull request Dec 26, 2023
Allow "aws cloudformation package" to succeed when a Resource is not a key-value pair.
@rhbecker
Copy link

A fix very similar to what this PR addressed is needed for the sam cli. Is there any chance that the authors of this PR would be willing to take that on?

smasset-veolia added a commit to smasset-veolia/serverless-application-model that referenced this pull request Aug 14, 2024
smasset-veolia added a commit to smasset-veolia/serverless-application-model that referenced this pull request Aug 14, 2024
smasset-veolia added a commit to smasset-veolia/serverless-application-model that referenced this pull request Aug 17, 2024
smasset-veolia added a commit to smasset-veolia/serverless-application-model that referenced this pull request Aug 20, 2024
dcabib added a commit to dcabib/aws-sam-cli that referenced this pull request Oct 6, 2025
Fixes the 2.5-year-old bug where SAM CLI crashed with AttributeError when processing templates using CloudFormation's Fn::ForEach.

Following AWS CLI's approach (aws/aws-cli#8096), we now detect and skip Fn::ForEach constructs during local parsing, letting CloudFormation expand them server-side.

Changes:
- Added Fn::ForEach to unresolvable intrinsics
- Updated resource metadata normalizer to skip ForEach blocks
- Added informative logging
- Updated providers to handle ForEach gracefully
- Added integration tests

Testing:
- All 5,870 unit tests pass
- 94.12% code coverage
- Verified with real templates

Closes aws#5647
@dcabib
Copy link

dcabib commented Oct 6, 2025

Hey everyone! 🎉

Just opened a PR that fixes this issue: PR ##5647

TL;DR: SAM CLI now supports Fn::ForEach! No more AttributeError crashes.

We followed the same approach AWS CLI took in their PR #8096 - detect ForEach constructs, skip them during local parsing, and let CloudFormation handle the expansion server-side (where it belongs).

Tested thoroughly:

  • ✅ 5,870 unit tests passing
  • ✅ 94% code coverage
  • ✅ Real templates with Fn::ForEach validate and build successfully
  • ✅ ForEach constructs preserved for CloudFormation

Been waiting 2.5 years for this one - should be good to go! 🚀

dcabib added a commit to dcabib/aws-sam-cli that referenced this pull request Oct 6, 2025
Fixes the 2.5-year-old bug where SAM CLI crashed with AttributeError when processing templates using CloudFormation's Fn::ForEach.

Following AWS CLI's approach (aws/aws-cli#8096), we now detect and skip Fn::ForEach constructs during local parsing, letting CloudFormation expand them server-side.

Changes:
- Added Fn::ForEach to unresolvable intrinsics
- Updated resource metadata normalizer to skip ForEach blocks
- Added informative logging
- Updated providers to handle ForEach gracefully
- Added integration tests

Testing:
- All 5,870 unit tests pass
- 94.12% code coverage
- Verified with real templates

Closes aws#5647
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.

6 participants