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 http://java-regex-tester.appspot.com This is much easier than doing it with CloudFormation.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

*

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden .