Class CfnJson
Captures a synthesis-time JSON object a CloudFormation reference which resolves during deployment to the resolved values of the JSON object.
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(Construct, string, ICfnJsonProps) | Captures a synthesis-time JSON object a CloudFormation reference which resolves during deployment to the resolved values of the JSON object. |
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(Construct, string, ICfnJsonProps)
Captures a synthesis-time JSON object a CloudFormation reference which resolves during deployment to the resolved values of the JSON object.
public CfnJson(Construct scope, string id, ICfnJsonProps props)
Parameters
- scope Construct
- id string
- props ICfnJsonProps
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 });
Properties
CreationStack
The creation stack of this resolvable which will be appended to errors thrown during resolution.
public virtual string[] CreationStack { get; }
Property Value
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
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
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
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