Class CfnResource
Represents a CloudFormation resource.
public class CfnResource : CfnRefElement, IConstruct, IConstruct, IDependable
- Inheritance
-
CfnResource
- Implements
-
IConstruct
- Derived
- Inherited Members
Examples
using Amazon.CDK;
class MyConstruct : Resource, ITaggable
{
public readonly void Tags = new TagManager(TagType.KEY_VALUE, "Whatever::The::Type");
public MyConstruct(Construct scope, string id) : base(scope, id)
{
new CfnResource(this, "Resource", new CfnResourceProps {
Type = "Whatever::The::Type",
Properties = new Dictionary<string, object> {
// ...
{ "Tags", Tags.RenderedTags }
}
});
}
}
Remarks
ExampleMetadata: infused
Constructors
CfnResource(Construct, string, ICfnResourceProps)
Creates a resource construct.
public CfnResource(Construct scope, string id, ICfnResourceProps props)
Parameters
scope
Constructid
stringprops
ICfnResourceProps
Properties
CfnOptions
Options for this resource, such as condition, update policy etc.
public virtual ICfnResourceOptions CfnOptions { get; }
Property Value
CfnProperties
protected virtual IDictionary<string, object> CfnProperties { get; }
Property Value
CfnResourceType
AWS resource type.
public virtual string CfnResourceType { get; }
Property Value
UpdatedProperites
Return properties modified after initiation.
protected virtual IDictionary<string, object> UpdatedProperites { get; }
Property Value
Remarks
Resources that expose mutable properties should override this function to collect and return the properties object for this resource.
Methods
AddDeletionOverride(string)
Syntactic sugar for addOverride(path, undefined)
.
public virtual void AddDeletionOverride(string path)
Parameters
path
stringThe path of the value to delete.
AddDependsOn(CfnResource)
Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.
public virtual void AddDependsOn(CfnResource target)
Parameters
target
CfnResource
Remarks
This can be used for resources across stacks (or nested stack) boundaries and the dependency will automatically be transferred to the relevant scope.
AddMetadata(string, object)
Add a value to the CloudFormation Resource Metadata.
public virtual void AddMetadata(string key, object value)
Parameters
Remarks
See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html
Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.
AddOverride(string, object)
Adds an override to the synthesized CloudFormation resource.
public virtual void AddOverride(string path, object value)
Parameters
path
string- The path of the property, you can use dot notation to override values in complex types.
value
object- The value.
Remarks
To add a
property override, either use addPropertyOverride
or prefix path
with
"Properties." (i.e. Properties.TopicName
).
If the override is nested, separate each nested level using a dot (.) in the path parameter. If there is an array as part of the nesting, specify the index in the path.
To include a literal .
in the property name, prefix with a </code>. In most
programming languages you will need to write this as
"\."
because the
</code> itself will need to be escaped.
For example,
cfnResource.AddOverride("Properties.GlobalSecondaryIndexes.0.Projection.NonKeyAttributes", new [] { "myattribute" });
cfnResource.AddOverride("Properties.GlobalSecondaryIndexes.1.ProjectionType", "INCLUDE");
would add the overrides
"Properties": {
"GlobalSecondaryIndexes": [
{
"Projection": {
"NonKeyAttributes": [ "myattribute" ]
...
}
...
},
{
"ProjectionType": "INCLUDE"
...
},
]
...
}
The value
argument to addOverride
will not be processed or translated
in any way. Pass raw JSON values in here with the correct capitalization
for CloudFormation. If you pass CDK classes or structs, they will be
rendered with lowercased key names, and CloudFormation will reject the
template.
AddPropertyDeletionOverride(string)
Adds an override that deletes the value of a property from the resource definition.
public virtual void AddPropertyDeletionOverride(string propertyPath)
Parameters
propertyPath
stringThe path to the property.
AddPropertyOverride(string, object)
Adds an override to a resource property.
public virtual void AddPropertyOverride(string propertyPath, object value)
Parameters
Remarks
Syntactic sugar for addOverride("Properties.<...>", value)
.
ApplyRemovalPolicy(RemovalPolicy?, IRemovalPolicyOptions?)
Sets the deletion policy of the resource based on the removal policy specified.
public virtual void ApplyRemovalPolicy(RemovalPolicy? policy = null, IRemovalPolicyOptions? options = null)
Parameters
policy
RemovalPolicy?options
IRemovalPolicyOptions
Remarks
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
GetAtt(string)
Returns a token for an runtime attribute of this resource.
public virtual Reference GetAtt(string attributeName)
Parameters
attributeName
stringThe name of the attribute.
Returns
Remarks
Ideally, use generated attribute accessors (e.g. resource.arn
), but this can be used for future compatibility
in case there is no generated attribute.
GetMetadata(string)
Retrieve a value value from the CloudFormation Resource Metadata.
public virtual object GetMetadata(string key)
Parameters
key
string
Returns
Remarks
See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html
Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.
IsCfnResource(IConstruct)
Check whether the given construct is a CfnResource.
public static bool IsCfnResource(IConstruct construct)
Parameters
construct
IConstruct
Returns
RenderProperties(IDictionary<string, object>)
protected virtual IDictionary<string, object> RenderProperties(IDictionary<string, object> props)
Parameters
props
IDictionary<string, object>
Returns
ShouldSynthesize()
Can be overridden by subclasses to determine if this resource will be rendered into the cloudformation template.
protected virtual bool ShouldSynthesize()
Returns
- bool
true
if the resource should be included orfalse
is the resource should be omitted.
ToString()
Returns a string representation of this construct.
public override string ToString()
Returns
- string
a string representation of this resource
ValidateProperties(object)
protected virtual void ValidateProperties(object properties)
Parameters
properties
object