!Select function documentation mentions following:
Fn::Select does not check for null values or if the index is out of bounds of the array. Both conditions will result in a stack error, so you should be certain that the index you choose is valid, and that the list contains non-null values.
Without the ability to check for the provided array length CloudFormation is impossible to implement some very simple solutions.
For example, I need to create an AWS::EFS::MountTarget for each user-provided subnet, but it is impossible because I can't know how many subnets user will provide.
For example:
Parameters:
Subnets:
Type: List<AWS::EC2::Subnet::Id>
Resources:
EFSMountTarget1:
Type: AWS::EFS::MountTarget
Properties:
FileSystemId: !Ref EFSVolume
SecurityGroups:
- !Ref EFSSecurityGroup
SubnetId: !Select [0, !Ref Subnets]
EFSMountTarget2:
Type: AWS::EFS::MountTarget
Properties:
FileSystemId: !Ref EFSVolume
SecurityGroups:
- !Ref EFSSecurityGroup
SubnetId: !Select [1, !Ref Subnets]
Will fail if the user will provide only one subnet.
Attempt to add the following condition:
Conditions:
IsSubnet1: !Not [!Equals [!Select [ 0, !Ref Subnets], !Ref AWS::NoValue ]]
IsSubnet2: !Not [!Equals [!Select [ 1, !Ref Subnets], !Ref AWS::NoValue ]]
Fails with the error: ValidationError: Template error: every Fn::Equals object requires a list of 2 string parameters.
Another attempt:
Conditions:
IsSubnet1: !Not [!Equals [!Select [ 0, !Ref Subnets], "" ]]
IsSubnet2: !Not [!Equals [!Select [ 1, !Ref Subnets], "" ]]
Fails with the error: ValidationError: Template error: Fn::Select cannot select nonexistent value at index 1
Would https://github.com/aws-cloudformation/aws-cloudformation-coverage-roadmap/issues/204, which requests Fn::Size, help?
Yes, as one of the ways to resolve the issue. Thanks.
This is, I think, a strong use case for a Fn::Map function.
I never considered asking for Fn:Map. It would solve a lot of my problems 馃く
If they are not adding the easier Fn::Size, no way in hell are they adding Fn::Map.
I'm persistent in leaving feedback :). I think Fn:Map fits a lot better with the declarative model in CloudFormation. It would solve more problems than Fn:Size and in a cleaner way (which is in line with how AWS likes to address things).
Most helpful comment
This is, I think, a strong use case for a
Fn::Mapfunction.