Skip to content

Feature request: Support LanguageExtensions feature Fn::ForEach #5647

Closed

Description

@twasink

It would be useful if the LanguageExtensions transform feature Fn::ForEach was supported with SAM CLI.

The documentation for the LanguageExtensions transforms states that you can use it with the Serverless transform:

If you're using multiple transforms, use a list format. If you're using custom macros, place AWS-provided transforms after your custom macros. If you're using both the AWS::LanguageExtensions and AWS::Serverless transforms, the AWS::LanguageExtensions transform must come before the AWS::Serverless transform in the list.

However, when you try to use the example for the Fn::ForEach function (with or without include the Serverless Transform), the sam-cli fails to understand the syntax.

Example template.yaml:

AWSTemplateFormatVersion: 2010-09-09
Transform: 
  - - AWS::LanguageExtensions
    - AWS::Serverless-2016-10-31
Resources:
  'Fn::ForEach::Topics':
    - TopicName
    - - Success
      - Failure
      - Timeout
      - Unknown
    - 'SnsTopic${TopicName}':
        Type: 'AWS::SNS::Topic'
        Properties:
          TopicName: !Ref TopicName
          FifoTopic: true

Example output from sam build:

$ sam build
2023-07-30 17:52:37 Plugin 'ServerlessAppPlugin' raised an exception: 'list' object has no attribute 'get'
Traceback (most recent call last):
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samtranslator/plugins/sam_plugins.py", line 130, in act
    getattr(plugin, method_name)(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samtranslator/metrics/method_decorator.py", line 116, in wrapper_cw_timer
    exec_result = func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samtranslator/plugins/application/serverless_app_plugin.py", line 124, in on_before_transform_template
    for logical_id, app in template.iterate({SamResourceType.Application.value}):
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samtranslator/sdk/template.py", line 34, in iterate
    resource = SamResource(resource_dict)
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samtranslator/sdk/resource.py", line 26, in __init__
    self.type = resource_dict.get("Type")
AttributeError: 'list' object has no attribute 'get'

Error: 'list' object has no attribute 'get'
Traceback:
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 184, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 149, in wrapped
    return_value = func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/version_checker.py", line 42, in wrapped
    actual_result = func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samcli/cli/main.py", line 95, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samcli/commands/build/command.py", line 166, in cli
    do_cli(
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samcli/commands/build/command.py", line 238, in do_cli
    with BuildContext(
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samcli/commands/build/build_context.py", line 184, in __enter__
    self.set_up()
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samcli/commands/build/build_context.py", line 190, in set_up
    self._stacks, remote_stack_full_paths = SamLocalStackProvider.get_stacks(
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samcli/lib/providers/sam_stack_provider.py", line 269, in get_stacks
    current = SamLocalStackProvider(
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samcli/lib/providers/sam_stack_provider.py", line 61, in __init__
    self._template_dict = self.get_template(
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samcli/lib/providers/sam_base_provider.py", line 193, in get_template
    template_dict = SamTranslatorWrapper(template_dict, parameter_values=parameters_values).run_plugins()
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samcli/lib/samlib/wrapper.py", line 73, in run_plugins
    parser.parse(template_copy, all_plugins)  # parse() will run all configured plugins
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samcli/lib/samlib/wrapper.py", line 130, in parse
    sam_plugins.act(LifeCycleEvents.before_transform_template, sam_template)
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samtranslator/plugins/sam_plugins.py", line 136, in act
    raise ex
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samtranslator/plugins/sam_plugins.py", line 130, in act
    getattr(plugin, method_name)(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samtranslator/metrics/method_decorator.py", line 116, in wrapper_cw_timer
    exec_result = func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samtranslator/plugins/application/serverless_app_plugin.py", line 124, in on_before_transform_template
    for logical_id, app in template.iterate({SamResourceType.Application.value}):
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samtranslator/sdk/template.py", line 34, in iterate
    resource = SamResource(resource_dict)
  File "/usr/local/Cellar/aws-sam-cli/1.94.0/libexec/lib/python3.8/site-packages/samtranslator/sdk/resource.py", line 26, in __init__
    self.type = resource_dict.get("Type")

An unexpected error was encountered while executing "sam build".
Search for an existing issue:
https://github.com/aws/aws-sam-cli/issues?q=is%3Aissue+is%3Aopen+Bug%3A%20sam%20build%20-%20AttributeError
Or create a bug report:
https://github.com/aws/aws-sam-cli/issues/new?template=Bug_report.md&title=Bug%3A%20sam%20build%20-%20AttributeError

(This was with SAM CLI version 1.94)

Activity

  1. added
    stage/needs-triage
    type/feature
    on Jul 30, 2023
  2. moelasmar commented on Jul 31, 2023

    @moelasmar
    Contributor

    Thanks @twasink for raising this issue. I will discuss this issue with the team to see how can we prioritize it.

  3. removed
    stage/needs-triage
    on Jul 31, 2023
  4. cortexcompiler commented on Aug 15, 2023

    @cortexcompiler

    I am also running into this. Would be nice to use Fn::ForEach to do some things similar to SAM serverless resources. I was hoping to add a group of AWS::Serverless::Function resources along with essentially templated LogGroup SubscriptionFilter resources for each of the functions. However, I immediately ran into this error trying to run sam build

  5. cortexcompiler commented on Aug 15, 2023

    @cortexcompiler

    Also, is this really a feature request? I would expect SAM to support native CloudFormation functions. I feel like this is actually a bug.

  6. AEkman commented on Aug 18, 2023

    @AEkman

    I can confirm that I have seen the same issue. When SAM is validating I get the following error:
    Error: 'list' object has no attribute 'get'

  7. AEkman commented on Aug 18, 2023

    @AEkman

    It would also be good to mention that it's currently not supported in documentation!

  8. ggiallo28 commented on Aug 24, 2023

    @ggiallo28

    I am running the same issue with "aws cloudformation package"

  9. maciejGolebio commented on Aug 29, 2023

    @maciejGolebio

    image

  10. ryanniuu commented on Sep 19, 2023

    @ryanniuu

    same issue when running "sam validate"
    i would say this is a bug not feature request

  11. nelsonmora48 commented on Oct 5, 2023

    @nelsonmora48

    Ya vamos por la 1.98 y aun no se corrige este problema

  12. francisreyes-tfs commented on Oct 6, 2023

    @francisreyes-tfs

    Pull request 8096 from aws-cli looks promising but needs review

  13. rhbecker commented on Jan 12, 2024

    @rhbecker

    PR 8096 (aws-cli) was merged in mid-December. A couple of comments on related issues here and here indicate that recent aws-cli versions no longer have this problem.

    Is the aws-cli "upstream" relative to sam-cli, meaning that we'll inevitably see this same fix in an imminent sam-cli releaes? Or does the sam-cli team need to independently address this issue?

    Regardless, I'm hoping this might be near the finish line, so that I don't need to train our staff on 2 different stack management tools. 🤞

  14. mlmland commented on Jan 17, 2024

    @mlmland

    I'm having this issue as well. Any updates?

  15. 25 remaining items

  16. added
    area/sync
    area/package
    on Jan 27, 2026
  17. bnusunny commented on Jan 30, 2026

    @bnusunny
    Contributor

    Thanks for filing this feature request, and apologies for the long wait — we know this has been open since 2023.

    Currently, SAM CLI processes templates locally, and when it encounters Fn::ForEach, the resource iteration logic expects each resource to be a dictionary with a Type key — but Fn::ForEach produces a list structure instead, which causes the error you're seeing.

    Good news: We're actively working on adding full AWS::LanguageExtensions transform support to SAM CLI. This will enable sam build, sam local invoke, and other local commands to properly expand Fn::ForEach loops and handle other Language Extensions features.

  18. abjoerne commented on Mar 5, 2026

    @abjoerne

    Any rough ETA on this? Is it Q1-26, H1-2026, H2-2026, 2027???

  19. anudas-pexa commented on Apr 30, 2026

    @anudas-pexa

    Any ETA on this? Also having this issue at the moment.

  20. github-actions commented on May 1, 2026

    @github-actions
    Contributor

    ⚠️COMMENT VISIBILITY WARNING⚠️

    Comments on closed issues are hard for our team to see.
    If you need more assistance, please either tag a team member or 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.

  21. reedham-aws commented on May 1, 2026

    @reedham-aws
    Contributor

    This will be released in SAM CLI v1.160.0.

  22. bnusunny commented on May 18, 2026

    @bnusunny
    Contributor

    This feature is fully launched. Here are the What's New and launch blog post.

    The implementation also supports dynamic artifact properties: When a packageable property uses a loop variable (for example, ./services/${Name}), the AWS SAM CLI generates a CloudFormation Mappings section that maps each collection value to its Amazon S3 URI. The Fn::ForEach body is rewritten to use Fn::FindInMap so CloudFormation can resolve the correct artifact at deploy time.

    Find out more in the developer guide.

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

    area/buildarea/localarea/packagearea/syncarea/validatetype/feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions