- Newest
- Most votes
- Most comments
CloudFormation validates the AllowedPattern constraint against the parameter value exactly as supplied, without trimming or normalization. When you supply a parameter value during stack creation, update, or change set execution, CloudFormation checks the AllowedPattern regular expression against the literal string you provide.
The behavior you observed with ValidateTemplate is specific to that API operation and does not reflect how parameter validation works during actual stack operations. ValidateTemplate performs only basic template syntax checking and does not execute the full parameter validation logic that runs during CreateStack, UpdateStack, or CreateChangeSet operations.
During actual stack operations, CloudFormation's pre-deployment validation runs multiple checks against your template and target environment. Property syntax validation—which includes AllowedPattern checking—runs on all CreateStack, UpdateStack, and CreateChangeSet operations. This validation operates in FAIL mode, meaning it stops the stack operation before any resources are provisioned if validation detects errors.
Your AllowedPattern constraint designed to reject values with trailing whitespace or carriage returns should function as intended during real deployments. If a user supplies a parameter value with trailing spaces, tabs, or newlines, CloudFormation will validate that exact string against your pattern. Since your pattern is anchored to reject trailing whitespace, the validation will fail and prevent the stack operation from proceeding.
Therefore, your constraint is a real control that will enforce your whitespace requirements at execution time. You do not need to replace it with an external deploy-time check.
Sources
Ship infrastructure faster with CloudFormation and CDK pre-deployment validation on every stack operation | AWS DevOps & Developer Productivity Blog
Validate stack deployments - AWS CloudFormation
AWS::SSM::Parameter - AWS CloudFormation
CloudFormation template Parameters syntax - AWS CloudFormation
Relevant content
asked 6 years ago
asked 6 years ago
