Skip to content

New Fn::ForEach function breaks cloudformation package CLI #8075

@JeremieRodon

Description

@JeremieRodon

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.cloudformationcloudformation package-deploycustomizationIssues related to CLI customizations (located in /awscli/customizations)p3This is a minor priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions