AWS CloudFormation Template Parameter Type Validation
24. February 2016

AWS Cloudformation has some nice features to validate parameter values. One can define some predefined types like AWS::EC2::VPC::Id or simple types like Number or String. Always use the predefined types if they are feasible for you because of them being maintained by AWS. If for example AWS introduces longer instance ID’s, you don’t have to modify your regex patterns but simply rely on somebody else doing so.

"Parameters" : {
  "vpcId" : {
    "Description" : "vpc id",
    "Type" : "AWS::EC2::VPC::Id"

For all other cases CloudFormation offers an AllowedPattern attribute for parameters. This is where you can use java.util.regex.Pattern expressions to validate values.

"Parameters" : {
  "hostedZoneName" : {
    "Description" : "Route53 hosted zone name",
    "Type" : "String",
    "AllowedPattern": ".*\\.$",
    "ConstraintDescription": "Must have a dot at the end"

Please note: All backslashes need an additional backslash to pass the JSON transformation!

See the following like for further documentation:

I usually test my regex expressions with tools like This is much easier than doing it with CloudFormation.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.