class CfnRule (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.CfnRule |
![]() | github.com/aws/aws-cdk-go/awscdk/v2#CfnRule |
![]() | software.amazon.awscdk.CfnRule |
![]() | aws_cdk.CfnRule |
![]() | aws-cdk-lib » CfnRule |
Implements
IConstruct
, IDependable
The Rules that define template constraints in an AWS Service Catalog portfolio describe when end users can use the template and which values they can specify for parameters that are declared in the AWS CloudFormation template used to create the product they are attempting to use.
Rules are useful for preventing end users from inadvertently specifying an incorrect value. For example, you can add a rule to verify whether end users specified a valid subnet in a given VPC or used m1.small instance types for test environments. AWS CloudFormation uses rules to validate parameter values before it creates the resources for the product.
A rule can include a RuleCondition property and must include an Assertions property. For each rule, you can define only one rule condition; you can define one or more asserts within the Assertions property. You define a rule condition and assertions by using rule-specific intrinsic functions.
Example
declare const cfnTemplate: cfn_inc.CfnInclude;
const rule: core.CfnRule = cfnTemplate.getRule('MyRule');
// mutating the rule
declare const myParameter: core.CfnParameter;
rule.addAssertion(core.Fn.conditionContains(['m1.small'], myParameter.valueAsString),
'MyParameter has to be m1.small');
Initializer
new CfnRule(scope: Construct, id: string, props?: CfnRuleProps)
Parameters
- scope
Construct
— The parent construct. - id
string
- props
Cfn
— The rule props.Rule Props
Creates and adds a rule.
Construct Props
Name | Type | Description |
---|---|---|
assertions? | Cfn [] | Assertions which define the rule. |
rule | ICfn | If the rule condition evaluates to false, the rule doesn't take effect. |
assertions?
Type:
Cfn
[]
(optional, default: No assertions for the rule.)
Assertions which define the rule.
ruleCondition?
Type:
ICfn
(optional, default: Rule's assertions will always take effect.)
If the rule condition evaluates to false, the rule doesn't take effect.
If the function in the rule condition evaluates to true, expressions in each assert are evaluated and applied.
Properties
Name | Type | Description |
---|---|---|
creation | string[] | |
logical | string | The logical ID for this CloudFormation stack element. |
node | Node | The tree node. |
ref | string | Return a string that will be resolved to a CloudFormation { Ref } for this element. |
stack | Stack | The stack in which this element is defined. |
creationStack
Type:
string[]
logicalId
Type:
string
The logical ID for this CloudFormation stack element.
The logical ID of the element is calculated from the path of the resource node in the construct tree.
To override this value, use overrideLogicalId(newLogicalId)
.
node
Type:
Node
The tree node.
ref
Type:
string
Return a string that will be resolved to a CloudFormation { Ref }
for this element.
If, by any chance, the intrinsic reference of a resource is not a string, you could
coerce it to an IResolvable through Lazy.any({ produce: resource.ref })
.
stack
Type:
Stack
The stack in which this element is defined.
CfnElements must be defined within a stack scope (directly or indirectly).
Methods
Name | Description |
---|---|
add | Adds an assertion to the rule. |
override | Overrides the auto-generated logical ID with a specific ID. |
to | Returns a string representation of this construct. |
addAssertion(condition, description)
public addAssertion(condition: ICfnConditionExpression, description: string): void
Parameters
- condition
ICfn
— The expression to evaluation.Condition Expression - description
string
— The description of the assertion.
Adds an assertion to the rule.
overrideLogicalId(newLogicalId)
public overrideLogicalId(newLogicalId: string): void
Parameters
- newLogicalId
string
— The new logical ID to use for this stack element.
Overrides the auto-generated logical ID with a specific ID.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.