aws / aws/aws-sam-cli

Feature request: Fn::ForEach support for generating array items (not just resources)

Open
#9,044 1 comment 0 reactions 0 assignees View on GitHub
type/feature
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

## Description

Community feedback from the [Language Extensions blog post](https://builder.aws.com/content/3DiJq5vQ2hnGq1ddBlCApT8uy6u/dynamic-looping-comes-to-aws-sam):

`Fn::ForEach` currently generates top-level resources, conditions, and outputs. However, developers also need to generate **array items within a resource property** from a collection.

## Use Case

DynamoDB tables have several array-typed properties (e.g., `AttributeDefinitions`, `GlobalSecondaryIndexes`, `ReplicaUpdates`) where each item follows the same structure but varies by a key value. Currently, these must be manually listed even when a parameter provides the collection.

Example (desired behavior):

```yaml
Parameters:
Attributes:
Type: CommaDelimitedList
Default: "id,name,email"

Resources:
MyTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
Fn::ForEach::Attrs:
- AttrName
- !Ref Attributes
- AttributeName: !Sub ${AttrName}
AttributeType: S
```

## Current Workaround

Users maintain custom CloudFormation macros: https://github.com/mlhpdx/cloudformation-macros

## Source

Comment by Lee Harding on AWS Builder Center blog post, May 2026.

## Related

- #8637 (Language Extensions support PR)
- #5647 (original Fn::ForEach request)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.