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
已提問 4 年前檢視次數 1010 次
1 個回答
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
已回答 4 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南