Reputation: 5140
When we define parameters and refer it within Resources, the existence of parameter value is only checked upon stack creation; and if we fail to mention parameter value, then the stack creation fails and rollback with exception such as below
Parameter validation failed: parameter value for parameter name xxx does not exist. Rollback requested by user.
I know why and is clear from the general requirement of parameters in AWS Cloud Formation document.
• Each parameter must be assigned a value at runtime for AWS CloudFormation to successfully provision the stack.
However, what I would like to is to indicate users to when they fail to mention parameter values much before stack creation.
Question: Is there a way by which we could enforce to enter parameter's value before proceeding with stack creation ?
For example, if we fail to mention stack name, console won't let you proceed. I would like something similar where it stop stack creation from proceeding if there a missing value. This image has nothing to do with my question; but to show you what I would like for my custom parameter to display in case of missing value
Update: If someone like similar feature then following are sample solutions where parameter 'Name' constrain use to enter least a char before proceeding and 'SecuritygroupIngressCIDR' enforce a valid IP.
Parameters:
Name:
Type: String
AllowedPattern: ^[a-zA-Z0-9]*$
MinLength: 1
SecurityGroupIngressCIDR:
Description: The IP address range that can be used to communicate to the EC2 instances
Type: String
MinLength: '9'
MaxLength: '18'
AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
Upvotes: 0
Views: 1796
Reputation: 238081
As @Paolo said, this is the way it is usually done. A complementary example would be:
Parameters:
Name:
Type: String
AllowedPattern: ^[a-zA-Z0-9]*$
MinLength: 1
It is worth nothing that this will only error out when you hit Create stack
which is the step 4 in the console. Not at the same time when you specify the parameters or stack name (Step 2).
Upvotes: 0
Reputation: 26014
You can combine AllowedPattern
and Constraint description
for the parameter.
From the documentation:
AllowedPattern
A regular expression that represents the patterns to allow for String types
ConstraintDescription
A string that explains a constraint when the constraint is violated.
Upvotes: 2