Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloudformation AllowedPattern match dots and hyphens

I am trying to get a Cloudformation script to enforce a valid url path which could contain version information. I am trying to match something like:

/mypath-1.2.1

I am using

"AllowedPattern": "/[/a-zA-Z0-9_\-\.]*", "Default": "mypath-1.2.1"

I have checked the regex against an online checker and it is fine but I am getting a "Template validation error: Template format error: JSON not well-formed" on the backslashes.

It will validate ok without the backslashes but fails on the default value not matching the regex

like image 419
Terry Avatar asked Feb 07 '23 04:02

Terry


1 Answers

AllowedPattern is a JSON string and must follow the JSON standard for strings.

Your AllowedPattern contains escape sequences like \- and \. which are invalid in JSON.

You need to escape the black slashes in the AllowedPattern to make this valid JSON;

"AllowedPattern": "/[/a-zA-Z0-9_\\-\\.]*"

The JSON specification only allows escape sequences that follow these rules;

JSON string

like image 178
georgealton Avatar answered Mar 05 '23 10:03

georgealton