Class CfnJson
Captures a synthesis-time JSON object a CloudFormation reference which resolves during deployment to the resolved values of the JSON object.
Inheritance
Implements
Namespace: Amazon.CDK
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class CfnJson : Construct, IResolvable
Syntax (vb)
Public Class CfnJson
Inherits Construct
Implements IResolvable
Remarks
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
Examples
var tagParam = new CfnParameter(this, "TagName");
var stringEquals = new CfnJson(this, "ConditionJson", new CfnJsonProps {
Value = new Dictionary<string, boolean> {
{ $"aws:PrincipalTag/{tagParam.valueAsString}", true }
}
});
var principal = new AccountRootPrincipal().WithConditions(new Dictionary<string, object> {
{ "StringEquals", stringEquals }
});
new Role(this, "MyRole", new RoleProps { AssumedBy = principal });
Synopsis
Constructors
CfnJson(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
CfnJson(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
CfnJson(Construct, String, ICfnJsonProps) |
Properties
CreationStack | The creation stack of this resolvable which will be appended to errors thrown during resolution. |
Value | An Fn::GetAtt to the JSON object passed through |
Methods
Resolve(IResolveContext) | Produce the Token's value at resolution time. |
ToJSON() | This is required in case someone JSON.stringifys an object which references this object. Otherwise, we'll get a cyclic JSON reference. |
Constructors
CfnJson(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected CfnJson(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
CfnJson(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected CfnJson(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
CfnJson(Construct, String, ICfnJsonProps)
public CfnJson(Construct scope, string id, ICfnJsonProps props)
Parameters
- scope Constructs.Construct
- id System.String
- props ICfnJsonProps
Properties
CreationStack
The creation stack of this resolvable which will be appended to errors thrown during resolution.
public virtual string[] CreationStack { get; }
Property Value
System.String[]
Remarks
This may return an array with a single informational element indicating how to get this property populated, if it was skipped for performance reasons.
Value
An Fn::GetAtt to the JSON object passed through value
and resolved during synthesis.
public virtual Reference Value { get; }
Property Value
Remarks
Normally there is no need to use this property since CfnJson
is an
IResolvable, so it can be simply used as a value.
Methods
Resolve(IResolveContext)
Produce the Token's value at resolution time.
public virtual object Resolve(IResolveContext context)
Parameters
- context IResolveContext
Returns
System.Object
ToJSON()
This is required in case someone JSON.stringifys an object which references this object. Otherwise, we'll get a cyclic JSON reference.
public virtual string ToJSON()
Returns
System.String