0

I wanted to have a regex to ensure user provides 2 elements to parameter which is List

AvailabilityZones: Description: List of Availability Zones to use for the subnets in the VPC. Only two Availability Zones are used for this deployment, and the logical order of your selections is preserved. Type: List<AWS::EC2::AvailabilityZone::Name> AllowedPattern: "(([a-zA-Z]+)-([a-zA-Z]+)-([0-9a-z]+))" ConstraintDescription: Two Availability Zones must be added.

The above pattern does not validate 2 entries. Can someone help share how to effectively handle this scenario.

Sasi
  • 83
  • 3
  • 14

1 Answers1

0

When you specify Type as List, AWS itself will handle validation of inputs and also ensures that input is list. So, removing AllowedPattern should resolve your issue.

Edit-1

Please check the following regex.

^[a-zA-Z]+-[a-zA-Z]+-[0-9a-z]+(?:,[a-zA-Z]+-[a-zA-Z]+-[0-9a-z]+)+$

It should solve your requirement.

Hope this helps.

krisnik
  • 1,406
  • 11
  • 18
  • Thanks, @krisnik. I want to error out if the user does not provide '2' elements to the list. And not able to find a pattern or other ways to error out if less than 2 elements are provided as inputs for this list. – Sasi Aug 28 '18 at 06:27
  • I had a hack for similar issue in my cf templates. What is your criteria? You allow only 2 inputs or do you accept inputs >= 2 ? – krisnik Aug 29 '18 at 08:20
  • my case needs >=2. – Sasi Aug 30 '18 at 10:10
  • @Sasi please check if edit 1 works. I have verified it in Online regex validator. – krisnik Aug 30 '18 at 19:02
  • Thank @krisnik for the regex. I am sorry it did not work in the cloudformation case. I have noticed below shown during cloudformation preview and it matches with the above regex, but I don't think list in cloudformation is using ',' as the separator (I tried other patterns colon, next line and ', ' but it did not work) AvailabilityZones us-east-2a,us-east-2b – Sasi Sep 01 '18 at 15:06
  • Hi @Sasi, missed the notification. How about trying it with Type: String? – krisnik Sep 05 '18 at 06:45
  • I think making it a string would work, but it adds complexity to end user to enter the right AZ's. – Sasi Sep 06 '18 at 08:39
  • https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html -- Documentation says you can use AllowedPattern only for String datatypes. Guess, this is the limitation which you have to work with. – krisnik Sep 06 '18 at 12:31