Class CfnJson
Captures a synthesis-time JSON object a CloudFormation reference which resolves during deployment to the resolved values of the JSON object.
public class CfnJson : Construct, IConstruct, IConstruct, IDependable, IResolvable
- Inheritance
-
CfnJson
- Implements
-
IConstruct
- Inherited Members
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 });
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
Constructors
CfnJson(Construct, string, ICfnJsonProps)
public CfnJson(Construct scope, string id, ICfnJsonProps props)
Parameters
scope
Constructid
stringprops
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
- 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 _)
Parameters
Returns
ToJSON()
This is required in case someone JSON.stringifys an object which refrences this object. Otherwise, we'll get a cyclic JSON reference.
public virtual string ToJSON()