Repository navigation
Description
Describe the bug
When using aws cloudformation package on a template file that uses Transform: AWS::LanguageExtensions with Fn::ForEach, the command fails with the message:
'list' object has no attribute 'get'
Expected Behavior
aws cloudformation package should accept any syntax accepted by the CloudFormation service engine.
Current Behavior
aws cloudformation package fails with 'list' object has no attribute 'get' when using a template with the Fn::ForEach language extension.
Reproduction Steps
This is a valid CloudFormation template that will create two InternetGateways:
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::LanguageExtensions
Resources:
Fn::ForEach::IGW:
- index
- ['A', 'B']
- IGW${index}:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: !Sub igw-${index}If you save that in a file named igws.yml and try this:
aws cloudformation package --template-file igws.yml --s3-bucket some-bucket --output-template-file igws-new.yml
It will throw the exception
Possible Solution
It fails because the Resource bloc usually only contains sub-objects like:
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
[clip...]
With the Fn::ForEach, we must define a list, like:
Resources:
Fn::ForEach::Subnets:
- index
- ['A', 'B']
- [clip...]
I guess the CLI parser is expecting anything under Resources to be a Python dictionary with a Type key so it tries to get that.
When it tries to do so on the Fn::ForEach list, that throws 'list' object has no attribute 'get'
Additional Information/Context
No response
CLI version used
aws-cli/2.13.5
Environment details (OS name and version, etc.)
Windows 10
Activity
JeremieRodon commentedon Jul 31, 2023
Update: It also fails when packaging a template with nested templates when one of the nested templates uses the
Fn::ForEachaBurmeseDev commentedon Aug 4, 2023
Hi @JeremieRodon - thanks for reporting this behavior. I was able to reproduce it on my end and we will need to further investigate with the team. I'll post here once we have an update.
aBurmeseDev commentedon Aug 8, 2023
From further discussion with the team, we have been advised to refer users of CloudFormation package to the AWS SAM CLI and sam-package command. Any changes related to the CloudFormation customization are currently not prioritized but you're welcome to submit contribution PR on this and the team will be able to take a look.
As an alternative, are you able to use the AWS SAM CLI or do you know if this issue present there as well?
dansepp-gale commentedon Aug 9, 2023
As best I can tell, this is an issue with the AWS SAM CLI as well.
richard-grainger-veeva commentedon Aug 11, 2023
I am also seeing this issue.
tim-finnigan commentedon Aug 15, 2023
Just wanted to follow up and let everyone know that we are aware of the issue, and the team owning the CloudFormation customization is planning to work on it. Also found a related issue in the SAM CLI repository: aws/aws-sam-cli#5647
hssyoo commentedon Jan 2, 2024
The
Fn::ForEachintrinsic function is available in v1 and v2: #8096github-actions commentedon Jan 2, 2024
Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.