跳至内容

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,

已提问 6 年前720 查看次数

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.

已回答 6 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。