Using CloudFormation Output as Fn::ForEach collection

21 views Asked by At

I have 1 x AWS ElastiCache Replication Group running Redis built using CloudFormation.

I have a CloudFormation Output as follows:

  ElastiCacheRedisReplicationGroupReaderEndPoints:
    Description: The reader endpoints for ElastiCache
    Value:
      Fn::GetAtt: ElastiCacheRedisReplicationGroup.ReadEndPoint.Addresses
    Export: 
      Name:
        Fn::Sub: ${AWS::StackName}-ReadEndpoints

(https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticache-replicationgroup.html#aws-resource-elasticache-replicationgroup-return-values)

The Output value is:

[redis-replication-group-001-001.******.0001.euw2.cache.amazonaws.com]

In another CloudFormation template I was hoping to use the Output value as the Collection within a Fn::ForEach intrinsic function to create CloudWatch Alarms like so:

  Fn::ForEach::ElastiCacheCPUUtilizationAlarms:
    - ReadEndpoint
    - Fn::ImportValue:
        Fn::Sub: ${ElastiCacheStackName}-ReadEndPoints
    - ElastiCacheCPUUtilizationAlarm&{ReadEndpoint}:
        Type: AWS::CloudWatch::Alarm
...(truncated)

When I update the CloudFormation stack I get an error: Transform AWS::LanguageExtensions failed with: Could not find a collection or could not be resolved for Fn::ForEach

However if I explicitly set the collection like this, it works:

  Fn::ForEach::ElastiCacheCPUUtilizationAlarms:
    - ReadEndpoint
    - - redis-replication-group-001-001.******.0001.euw2.cache.amazonaws.com:6379
    - ElastiCacheCPUUtilizationAlarm&{ReadEndpoint}:
        Type: AWS::CloudWatch::Alarm
...(truncated)

Is it the square brackets causing the problem? I don't understand why it can't see the imported value as a single value like when I explicitly define it.

0

There are 0 answers