class CfnJson (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.CfnJson |
![]() | github.com/aws/aws-cdk-go/awscdk/v2#CfnJson |
![]() | software.amazon.awscdk.CfnJson |
![]() | aws_cdk.CfnJson |
![]() | aws-cdk-lib » CfnJson |
Implements
IConstruct
, IDependable
, IResolvable
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.
Example
const tagParam = new CfnParameter(this, 'TagName');
const stringEquals = new CfnJson(this, 'ConditionJson', {
value: {
[`aws:PrincipalTag/${tagParam.valueAsString}`]: true,
},
});
const principal = new iam.AccountRootPrincipal().withConditions({
StringEquals: stringEquals,
});
new iam.Role(this, 'MyRole', { assumedBy: principal });
Initializer
new CfnJson(scope: Construct, id: string, props: CfnJsonProps)
Parameters
- scope
Construct
- id
string
- props
Cfn
Json Props
Construct Props
Name | Type | Description |
---|---|---|
value | any | The value to resolve. |
value
Type:
any
The value to resolve.
Can be any JavaScript object, including tokens and references in keys or values.
Properties
Name | Type | Description |
---|---|---|
creation | string[] | The creation stack of this resolvable which will be appended to errors thrown during resolution. |
node | Node | The tree node. |
value | Reference | An Fn::GetAtt to the JSON object passed through value and resolved during synthesis. |
creationStack
Type:
string[]
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
Type:
Node
The tree node.
value
Type:
Reference
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.
Methods
Name | Description |
---|---|
resolve(_context) | Produce the Token's value at resolution time. |
to | This is required in case someone JSON.stringifys an object which references this object. Otherwise, we'll get a cyclic JSON reference. |
to | Returns a string representation of this construct. |
resolve(_context)
public resolve(_context: IResolveContext): any
Parameters
- _context
IResolve
Context
Returns
any
Produce the Token's value at resolution time.
toJSON()
public toJSON(): string
Returns
string
This is required in case someone JSON.stringifys an object which references this object. Otherwise, we'll get a cyclic JSON reference.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.