Class CfnResource
Represents a CloudFormation resource.
Inheritance
Inherited Members
Namespace: Amazon.CDK
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class CfnResource : CfnRefElement
Syntax (vb)
Public Class CfnResource Inherits CfnRefElement
Remarks
ExampleMetadata: infused
Examples
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 }
}
});
}
}
Synopsis
Constructors
| CfnResource(Construct, string, ICfnResourceProps) | Creates a resource construct. |
Properties
| CfnOptions | Options for this resource, such as condition, update policy etc. |
| CfnProperties | Represents a CloudFormation resource. |
| CfnResourceType | AWS resource type. |
| Env | Represents a CloudFormation resource. |
| UpdatedProperites | (deprecated) Deprecated. |
| UpdatedProperties | Return properties modified after initiation. |
Methods
| AddDeletionOverride(string) | Syntactic sugar for |
| AddDependency(CfnResource) | Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned. |
| AddDependsOn(CfnResource) | (deprecated) Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned. |
| AddMetadata(string, object) | Add a value to the CloudFormation Resource Metadata. |
| AddOverride(string, object) | Adds an override to the synthesized CloudFormation resource. |
| AddPropertyDeletionOverride(string) | Adds an override that deletes the value of a property from the resource definition. |
| AddPropertyOverride(string, object) | Adds an override to a resource property. |
| ApplyRemovalPolicy(RemovalPolicy?, IRemovalPolicyOptions?) | Sets the deletion policy of the resource based on the removal policy specified. |
| GetAtt(string, ResolutionTypeHint?) | Returns a token for an runtime attribute of this resource. |
| GetMetadata(string) | Retrieve a value value from the CloudFormation Resource Metadata. |
| IsCfnResource(object) | Check whether the given object is a CfnResource. |
| ObtainDependencies() | Retrieves an array of resources this resource depends on. |
| ObtainResourceDependencies() | Get a shallow copy of dependencies between this resource and other resources in the same stack. |
| RemoveDependency(CfnResource) | Indicates that this resource no longer depends on another resource. |
| RenderProperties(IDictionary<string, object>) | Represents a CloudFormation resource. |
| ReplaceDependency(CfnResource, CfnResource) | Replaces one dependency with another. |
| ShouldSynthesize() | Can be overridden by subclasses to determine if this resource will be rendered into the cloudformation template. |
| ToString() | Returns a string representation of this construct. |
| ValidateProperties(object) | Represents a CloudFormation resource. |
Constructors
CfnResource(Construct, string, ICfnResourceProps)
Creates a resource construct.
public CfnResource(Construct scope, string id, ICfnResourceProps props)
Parameters
- scope Construct
- id string
- props ICfnResourceProps
Remarks
ExampleMetadata: infused
Properties
CfnOptions
Options for this resource, such as condition, update policy etc.
public virtual ICfnResourceOptions CfnOptions { get; }
Property Value
Remarks
ExampleMetadata: infused
CfnProperties
Represents a CloudFormation resource.
protected virtual IDictionary<string, object> CfnProperties { get; }
Property Value
Remarks
ExampleMetadata: infused
Examples
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 }
}
});
}
}
CfnResourceType
AWS resource type.
public virtual string CfnResourceType { get; }
Property Value
Remarks
ExampleMetadata: infused
Env
Represents a CloudFormation resource.
public virtual IResourceEnvironment Env { get; }
Property Value
Remarks
ExampleMetadata: infused
Examples
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 }
}
});
}
}
UpdatedProperites
(deprecated) Deprecated.
[Obsolete("use `updatedProperties` Return properties modified after initiation Resources that expose mutable properties should override this function to collect and return the properties object for this resource.")]
protected virtual IDictionary<string, object> UpdatedProperites { get; }
Property Value
Remarks
Stability: Deprecated
UpdatedProperties
Return properties modified after initiation.
protected virtual IDictionary<string, object> UpdatedProperties { 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 string
The path of the value to delete.
Remarks
ExampleMetadata: infused
AddDependency(CfnResource)
Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.
public virtual void AddDependency(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.
AddDependsOn(CfnResource)
(deprecated) Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.
[Obsolete("use addDependency")]
public virtual void AddDependsOn(CfnResource target)
Parameters
- target CfnResource
Remarks
Stability: Deprecated
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 string
The path to the property.
Remarks
ExampleMetadata: infused
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). In some
cases, a snapshot can be taken of the resource prior to deletion
(RemovalPolicy.SNAPSHOT). A list of resources that support this policy
can be found in the following link:
GetAtt(string, ResolutionTypeHint?)
Returns a token for an runtime attribute of this resource.
public virtual Reference GetAtt(string attributeName, ResolutionTypeHint? typeHint = null)
Parameters
- attributeName string
The name of the attribute.
- typeHint ResolutionTypeHint?
The 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(object)
Check whether the given object is a CfnResource.
public static bool IsCfnResource(object x)
Parameters
- x object
Returns
Remarks
ExampleMetadata: infused
ObtainDependencies()
Retrieves an array of resources this resource depends on.
public virtual object[] ObtainDependencies()
Returns
object[]
Type union: (either Stack or CfnResource)[]
Remarks
This assembles dependencies on resources across stacks (including nested stacks) automatically.
ObtainResourceDependencies()
Get a shallow copy of dependencies between this resource and other resources in the same stack.
public virtual CfnResource[] ObtainResourceDependencies()
Returns
Remarks
ExampleMetadata: infused
RemoveDependency(CfnResource)
Indicates that this resource no longer depends on another resource.
public virtual void RemoveDependency(CfnResource target)
Parameters
- target CfnResource
Remarks
This can be used for resources across stacks (including nested stacks) and the dependency will automatically be removed from the relevant scope.
RenderProperties(IDictionary<string, object>)
Represents a CloudFormation resource.
protected virtual IDictionary<string, object> RenderProperties(IDictionary<string, object> props)
Parameters
- props IDictionary<string, object>
Returns
Remarks
ExampleMetadata: infused
Examples
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 }
}
});
}
}
ReplaceDependency(CfnResource, CfnResource)
Replaces one dependency with another.
public virtual void ReplaceDependency(CfnResource target, CfnResource newTarget)
Parameters
- target CfnResource
The dependency to replace.
- newTarget CfnResource
The new dependency to add.
Remarks
ExampleMetadata: infused
ShouldSynthesize()
Can be overridden by subclasses to determine if this resource will be rendered into the cloudformation template.
protected virtual bool ShouldSynthesize()
Returns
true if the resource should be included or false is the resource
should be omitted.
Remarks
ExampleMetadata: infused
ToString()
Returns a string representation of this construct.
public override string ToString()
Returns
a string representation of this resource
Remarks
ExampleMetadata: infused
ValidateProperties(object)
Represents a CloudFormation resource.
protected virtual void ValidateProperties(object properties)
Parameters
- properties object
Remarks
ExampleMetadata: infused
Examples
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 }
}
});
}
}