I am struggling with specifying a regular expression for email parameter of Cloudformation :

  MyEmail :
    Type: String
    Description: Email for notifications
    AllowedPattern: /[^\s@]+@[^\s@]+\.[^\s@]+/
    ConstraintDescription: You should enter a valid email

As you see, I tried /[^\s@]+@[^\s@]+\.[^\s@]+/ and it won't work.

What is the regular expression for emails in Cloudformation template ?

2 Answers 2



Since AWS CloudFormation templates use the JSON syntax for specifying objects and data, you will need to add an additional backslash to any backslash characters in your regular expression, or JSON will interpret these as escape characters.

For example, if you include a \d in your regular expression to match a digit character, you will need to write it as \\d in your JSON template.


The very same applies to your \s expressions. Use \\s and it works.


Looking back the question I started to wonder the missing quotation marks on your definition. I found out the expessions are yaml format that is the second way to define things in aws.

If you should follow the yaml syntax, the right way to give string values is like this:

AllowedPattern = '/[^\s@]+@[^\s@]+\.[^\s@]+/'



Use quotes if your value includes special characters, (e.g. :, {, }, [, ], ,, &, *, #, ?, |, -, <, >, =, !, %, @, ).


  • 1
    AWS documentation does not include starting / and trailing / slashes Oct 16, 2018 at 5:15

This worked for me in YAML format

    Description: Email for notifications
    Type: String
    AllowedPattern: '[^@]+@[^@]+\.[^@]+'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.