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(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
CfnResource(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
CfnResource(Construct, String, ICfnResourceProps) | Creates a resource construct. |
Properties
CfnOptions | Options for this resource, such as condition, update policy etc. |
CfnProperties | |
CfnResourceType | AWS resource type. |
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(Nullable<RemovalPolicy>, IRemovalPolicyOptions) | Sets the deletion policy of the resource based on the removal policy specified. |
GetAtt(String, Nullable<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>) | |
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) |
Constructors
CfnResource(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected CfnResource(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
CfnResource(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected CfnResource(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
CfnResource(Construct, String, ICfnResourceProps)
Creates a resource construct.
public CfnResource(Construct scope, string id, ICfnResourceProps props)
Parameters
- scope Constructs.Construct
- id System.String
- props 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
System.Collections.Generic.IDictionary<System.String, System.Object>
CfnResourceType
AWS resource type.
public virtual string CfnResourceType { get; }
Property Value
System.String
UpdatedProperites
(deprecated) Deprecated.
protected virtual IDictionary<string, object> UpdatedProperites { get; }
Property Value
System.Collections.Generic.IDictionary<System.String, System.Object>
Remarks
Stability: Deprecated
UpdatedProperties
Return properties modified after initiation.
protected virtual IDictionary<string, object> UpdatedProperties { get; }
Property Value
System.Collections.Generic.IDictionary<System.String, System.Object>
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 System.String
The path of the value to delete.
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.
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
- key System.String
- value System.Object
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 System.String
- The path of the property, you can use dot notation to override values in complex types.
- value System.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
For example, would add the overrides The .
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.
cfnResource.AddOverride("Properties.GlobalSecondaryIndexes.0.Projection.NonKeyAttributes", new [] { "myattribute" });
cfnResource.AddOverride("Properties.GlobalSecondaryIndexes.1.ProjectionType", "INCLUDE");
"Properties": {
"GlobalSecondaryIndexes": [
{
"Projection": {
"NonKeyAttributes": [ "myattribute" ]
...
}
...
},
{
"ProjectionType": "INCLUDE"
...
},
]
...
}
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 System.String
The path to the property.
AddPropertyOverride(String, Object)
Adds an override to a resource property.
public virtual void AddPropertyOverride(string propertyPath, object value)
Parameters
- propertyPath System.String
The path of the property.
- value System.Object
The value.
Remarks
Syntactic sugar for addOverride("Properties.<...>", value)
.
ApplyRemovalPolicy(Nullable<RemovalPolicy>, IRemovalPolicyOptions)
Sets the deletion policy of the resource based on the removal policy specified.
public virtual void ApplyRemovalPolicy(Nullable<RemovalPolicy> policy = null, IRemovalPolicyOptions options = null)
Parameters
- policy System.Nullable<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, Nullable<ResolutionTypeHint>)
Returns a token for an runtime attribute of this resource.
public virtual Reference GetAtt(string attributeName, Nullable<ResolutionTypeHint> typeHint = null)
Parameters
- attributeName System.String
The name of the attribute.
- typeHint System.Nullable<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 System.String
Returns
System.Object
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 System.Object
Returns
System.Boolean
ObtainDependencies()
Retrieves an array of resources this resource depends on.
public virtual object[] ObtainDependencies()
Returns
System.Object[]
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
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>)
protected virtual IDictionary<string, object> RenderProperties(IDictionary<string, object> props)
Parameters
- props System.Collections.Generic.IDictionary<System.String, System.Object>
Returns
System.Collections.Generic.IDictionary<System.String, System.Object>
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.
ShouldSynthesize()
Can be overridden by subclasses to determine if this resource will be rendered into the cloudformation template.
protected virtual bool ShouldSynthesize()
Returns
System.Boolean
true
if the resource should be included or false
is the resource
should be omitted.
ToString()
Returns a string representation of this construct.
public override string ToString()
Returns
System.String
a string representation of this resource
ValidateProperties(Object)
protected virtual void ValidateProperties(object properties)
Parameters
- properties System.Object