Undocumented feature: Using Template Constraint Rules in CloudFormation

08/01/2019
08/01/2019 Ben Bridts

Last month there was a post on the AWS Management Tools blog about how you can use Template Constraint Rules in CloudFormation.

Template Constraints is a Service Catalog feature that allows you to validate the values of different parameters against each other. While this is well documented in the Service Catalog documentation, it isn’t mentioned in the CloudFormation Template Anatomy at all.

However, after testing it for myself, I can confirm that it does indeed work in “pure” CloudFormation. I encourage you to read the full post, but here is a simple example that will only deploy if both parameters have the same value:

Parameters:
  CanBeAnything:
    Type: String
  MustBeTheSame:
    Type: String
Rules:
  ValidateEqual:
    Assertions:
      - AssertDescription: Both parameters must be the same
        Assert:
          "Fn::Equals":
            - !Ref CanBeAnything
            - !Ref MustBeTheSame
Resources:
  DummyResource:
    Type: "AWS::SSM::Parameter"
    Properties:
      Type: "String"
      Value: !Ref CanBeAnything

Using two different values will give you the AssertDescription as an error:

It’s easy to write more complex assertions, as both the syntax and the available functions (there are more functions available than the CloudFormation Condition Functions) can be found in the Service Catalog documentation.

  • SHARE

Comment (1)

  1. Steve Kinsman

    Thanks for blogging that Ben, it’s always fun to play with new things in CloudFormation!

Leave a Reply

Your email address will not be published. Required fields are marked *

LET'S WORK
TOGETHER

Need a hand? Or a high five?
Feel free to visit our offices and come say hi
… or just drop us a message

We are ready when you are

Cloudar – Operations

Veldkant 7
2550 Kontich (Antwerp)
Belgium

info @ cloudar.be

+32 3 450 67 18

Cloudar – HQ

Veldkant 33A
2550 Kontich (Antwerp)
Belgium

VAT BE0564 763 890

    This contact form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

    contact
    • SHARE