Skip to content

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

Closed

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

Activity

  1. added
    bug
    needs-triage
    on Jul 31, 2023
  2. JeremieRodon commented on Jul 31, 2023

    @JeremieRodon
    Author

    Update: It also fails when packaging a template with nested templates when one of the nested templates uses the Fn::ForEach

  3. self-assigned this
    on Aug 2, 2023
  4. added
    investigating
    and removed
    needs-triage
    on Aug 3, 2023
  5. aBurmeseDev commented on Aug 4, 2023

    @aBurmeseDev
    Contributor

    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.

  6. added
    p2
    on Aug 4, 2023
  7. aBurmeseDev commented on Aug 8, 2023

    @aBurmeseDev
    Contributor

    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?

  8. added
    p3
    response-requested
    and removed
    investigating
    p2
    on Aug 8, 2023
  9. dansepp-gale commented on Aug 9, 2023

    @dansepp-gale

    As best I can tell, this is an issue with the AWS SAM CLI as well.

  10. richard-grainger-veeva commented on Aug 11, 2023

    @richard-grainger-veeva

    I am also seeing this issue.

  11. tim-finnigan commented on Aug 15, 2023

    @tim-finnigan
    Contributor

    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

  12. added
    customization
    and removed
    response-requested
    on Aug 15, 2023
  13. removed their assignment
    on Aug 22, 2023
  14. hssyoo commented on Jan 2, 2024

    @hssyoo
    Contributor

    The Fn::ForEach intrinsic function is available in v1 and v2: #8096

  15. github-actions commented on Jan 2, 2024

    @github-actions
    Contributor

    ⚠️COMMENT VISIBILITY WARNING⚠️

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcloudformationcloudformation package-deploycustomizationp3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions