CfnRule L1 construct
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');
# cfn_template: cfn_inc.CfnInclude
# mutating the rule
# my_parameter: core.CfnParameter
rule = cfn_template.get_rule("MyRule")
rule.add_assertion(core.Fn.condition_contains(["m1.small"], my_parameter.value_as_string), "MyParameter has to be m1.small")
CfnInclude cfnTemplate;
// mutating the rule
CfnParameter myParameter;
CfnRule rule = cfnTemplate.getRule("MyRule");
rule.addAssertion(Fn.conditionContains(List.of("m1.small"), myParameter.getValueAsString()), "MyParameter has to be m1.small");
// Install: dotnet add package Amazon.CDK.Lib
CfnInclude cfnTemplate;
// mutating the rule
CfnParameter myParameter;
var rule = cfnTemplate.GetRule("MyRule");
rule.AddAssertion(Fn.ConditionContains(new [] { "m1.small" }, myParameter.ValueAsString), "MyParameter has to be m1.small");
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var cfnTemplate CfnInclude
// mutating the rule
var myParameter CfnParameter
rule := cfnTemplate.GetRule(jsii.String("MyRule"))
rule.AddAssertion(core.Fn_ConditionContains([]*string{
jsii.String("m1.small"),
}, myParameter.valueAsString), jsii.String("MyParameter has to be m1.small"))
Initializer
new CfnRule(scope: Construct, id: string, props?: CfnRuleProps)
CfnRule(scope: Construct, id: str, props: typing.Optional[CfnRuleProps] = None)
new CfnRule(Construct scope, String id, CfnRuleProps props)
new CfnRule(Construct scope, string id, CfnRuleProps? props = null)
NewCfnRule(Scope Construct, Id *string, Props CfnRuleProps)
Construct Props
assertionsCfnRuleAssertion[]assertionstyping.List[CfnRuleAssertion]assertionsList<CfnRuleAssertion>AssertionsCfnRuleAssertion[]Assertions*[]CfnRuleAssertion= No assertions for the rule.#ruleConditionICfnConditionExpressionrule_conditionICfnConditionExpressionruleConditionICfnConditionExpressionRuleConditionICfnConditionExpressionRuleConditionICfnConditionExpression= Rule's assertions will always ta…#If the function in the rule condition evaluates to true, expressions in each assert are evaluated and applied.
default
Default: Rule's assertions will always take effect.
Properties
creationStackstring[]creation_stacktyping.List[str]creationStackList<String>CreationStackstring[]CreationStack*[]*stringrequired#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).
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 }).
Methods
addAssertion(condition: ICfnConditionExpression, description: string): voiddef add_assertion(self, condition: ICfnConditionExpression, description: str) -> Nonepublic void addAssertion(ICfnConditionExpression condition, String description)public void AddAssertion(ICfnConditionExpression condition, string description)func AddAssertion(Condition ICfnConditionExpression, Description *string)#2 parameters
Parameters
conditionconditionconditionconditionCondition— The expression to evaluation.descriptiondescriptiondescriptiondescriptionDescription— The description of the assertion.
isCfnElement(x: any): boolean@staticmethod def is_cfn_element(x: Any) -> boolpublic static Boolean isCfnElement(Object x)public static bool IsCfnElement(object x)func IsCfnElement(X interface{}) *boolstatic#Uses duck-typing instead of instanceof to allow stack elements from different versions of this library to be included in the same stack.
returns
Returns: The construct as a stack element or undefined if it is not a stack element.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#notes · 1 parameter · returns
Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.
Parameters
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
overrideLogicalId(newLogicalId: string): voiddef override_logical_id(self, new_logical_id: str) -> Nonepublic void overrideLogicalId(String newLogicalId)public void OverrideLogicalId(string newLogicalId)func OverrideLogicalId(NewLogicalId *string)#1 parameter
Parameters
newLogicalIdnew_logical_idnewLogicalIdnewLogicalIdNewLogicalId— The new logical ID to use for this stack element.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.