CfnJson
- class aws_cdk.CfnJson(scope, id, *, value)
Bases:
Construct
Captures a synthesis-time JSON object a CloudFormation reference which resolves during deployment to the resolved values of the JSON object.
The main use case for this is to overcome a limitation in CloudFormation that does not allow using intrinsic functions as dictionary keys (because dictionary keys in JSON must be strings). Specifically this is common in IAM conditions such as
StringEquals: { lhs: "rhs" }
where you want “lhs” to be a reference.This object is resolvable, so it can be used as a value.
This construct is backed by a custom resource.
- ExampleMetadata:
infused
Example:
tag_param = CfnParameter(self, "TagName") string_equals = CfnJson(self, "ConditionJson", value={ "f"aws:PrincipalTag/{tagParam.valueAsString}"": True } ) principal = iam.AccountRootPrincipal().with_conditions({ "StringEquals": string_equals }) iam.Role(self, "MyRole", assumed_by=principal)
- Parameters:
scope (
Construct
) –id (
str
) –value (
Any
) – The value to resolve. Can be any JavaScript object, including tokens and references in keys or values.
Methods
- resolve(_context)
Produce the Token’s value at resolution time.
- Parameters:
_context (
IResolveContext
) –- Return type:
Any
- to_json()
This is required in case someone JSON.stringifys an object which references this object. Otherwise, we’ll get a cyclic JSON reference.
- Return type:
str
- to_string()
Returns a string representation of this construct.
- Return type:
str
Attributes
- creation_stack
The creation stack of this resolvable which will be appended to errors thrown during resolution.
This may return an array with a single informational element indicating how to get this property populated, if it was skipped for performance reasons.
- node
The tree node.
- value
An Fn::GetAtt to the JSON object passed through
value
and resolved during synthesis.Normally there is no need to use this property since
CfnJson
is an IResolvable, so it can be simply used as a value.
Static Methods
- classmethod is_construct(x)
Checks if
x
is a construct.Use this method instead of
instanceof
to properly detectConstruct
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 classConstruct
in each copy of theconstructs
library is seen as a different class, and an instance of one class will not test asinstanceof
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 theconstructs
library can be accidentally installed, andinstanceof
will behave unpredictably. It is safest to avoid usinginstanceof
, and using this type-testing method instead.- Parameters:
x (
Any
) – Any object.- Return type:
bool
- Returns:
true if
x
is an object created from a class which extendsConstruct
.