Table of Contents

Class Resource

Namespace
Amazon.CDK
Assembly
Amazon.CDK.dll

A construct which represents an AWS resource.

public abstract class Resource : Construct, IResource, IConstruct, IConstruct, IDependable
Inheritance
Resource
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

Resource(Construct, string, IResourceProps?)

protected Resource(Construct scope, string id, IResourceProps? props = null)

Parameters

scope Construct
id string
props IResourceProps

Properties

Env

The environment this resource belongs to.

public virtual IResourceEnvironment Env { get; }

Property Value

IResourceEnvironment

Remarks

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.

PhysicalName

Returns a string-encoded token that resolves to the physical name that should be passed to the CloudFormation resource.

protected virtual string PhysicalName { get; }

Property Value

string

Remarks

This value will resolve to one of the following:

    Stack

    The stack in which this resource is defined.

    public virtual Stack Stack { get; }

    Property Value

    Stack

    Methods

    ApplyRemovalPolicy(RemovalPolicy)

    Apply the given removal policy to this resource.

    public virtual void ApplyRemovalPolicy(RemovalPolicy policy)

    Parameters

    policy RemovalPolicy

    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).

    GeneratePhysicalName()

    protected virtual string GeneratePhysicalName()

    Returns

    string

    GetResourceArnAttribute(string, IArnComponents)

    Returns an environment-sensitive token that should be used for the resource's "ARN" attribute (e.g. bucket.bucketArn).

    protected virtual string GetResourceArnAttribute(string arnAttr, IArnComponents arnComponents)

    Parameters

    arnAttr string

    The CFN attribute which resolves to the ARN of the resource.

    arnComponents IArnComponents

    The format of the ARN of this resource.

    Returns

    string

    Remarks

    Normally, this token will resolve to arnAttr, but if the resource is referenced across environments, arnComponents will be used to synthesize a concrete ARN with the resource's physical name. Make sure to reference this.physicalName in arnComponents.

    GetResourceNameAttribute(string)

    Returns an environment-sensitive token that should be used for the resource's "name" attribute (e.g. bucket.bucketName).

    protected virtual string GetResourceNameAttribute(string nameAttr)

    Parameters

    nameAttr string

    The CFN attribute which resolves to the resource's name.

    Returns

    string

    Remarks

    Normally, this token will resolve to nameAttr, but if the resource is referenced across environments, it will be resolved to this.physicalName, which will be a concrete name.

    IsResource(IConstruct)

    Check whether the given construct is a Resource.

    public static bool IsResource(IConstruct construct)

    Parameters

    construct IConstruct

    Returns

    bool