AWS::EC2::AvailabilityZone::Name Parameter Validation...

0

I have an AWS::EC2::AvailabilityZone::Name as a parameter for my CloudFormation template like this:

AvailabilityZone:
Type: AWS::EC2::AvailabilityZone::Name
Description: New subnets will be created for this zone.
ConstraintDescription: "A valid availability zone must be selected."

It populates nicely with the list of Availability Zones for the region where the CloudFormation template is coming up. However, CloudFormation does not validate that an Availability Zone was selected (i.e. it can be left blank). After the "Create Stack" button is pushed the stack creation process will fail.

I would like to be able to validate the parameter and make sure that it is not empty before the stack fails. I tried specifying a "MinLength" property of 9. I uploaded the template and it would not let me enter an empty Availability Zone (i.e. it seemed to work). However, in our build process we call cfn-lint to validate the template and it gives the following error:

E2001 Parameter AvailabilityZone has property MinLength which is only valid for \['String']

Can anyone tell me what is the correct way to validate an AWS::EC2::AvailabilityZone::Name field to be non empty at least, and preferably an item in the list provided by the GUI?

Thanks in advance,

Edited by: hdsiii on May 15, 2020 11:24 AM

Edited by: hdsiii on May 15, 2020 11:26 AM

Edited by: hdsiii on May 18, 2020 4:24 PM

hdsiii
asked 4 years ago996 views
1 Answer
0

AWS tech support sent me an answer. Although MinLength is not supported on AvailabilityZone::Name, AllowedPattern is. Here is a pattern that ensures the AvailabilityZone::Name is at least 1 character long. Since this is a popup field it ensures that the popup is populated and not left blank.

===================================================
AvailabilityZone:
Type: AWS::EC2::AvailabilityZone::Name
Description: EC2 AvailabilityZone
AllowedPattern: ".+" # -> to have a non blank value

FYI: Using a DefaultValue is not really an option since I don't know what Region the script is being run in.

hdsiii
answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions