class Resource
Language | Type name |
---|---|
.NET | Amazon.CDK.Resource |
Java | software.amazon.awscdk.core.Resource |
Python | aws_cdk.core.Resource |
TypeScript (source) | @aws-cdk/core » Resource |
Implements
IConstruct
, IConstruct
, IDependable
, IResource
Extends
Construct
Implemented by
App
, Branch
, Domain
, Api
, Base
, Cognito
, Deployment
, Domain
, Gateway
, Lambda
, Method
, Model
, Proxy
, Rate
, Request
, Request
, Resource
, Rest
, Spec
, Stage
, Step
, Token
, Usage
, Vpc
, Api
, Domain
, Http
, Http
, Http
, Http
, Http
, Vpc
, Web
, Web
, Web
, Web
, Web
, Scalable
, Gateway
, Mesh
, Route
, Virtual
, Virtual
, Virtual
, Virtual
, Service
, Vpc
, Appsync
, Graphql
, Auto
, Lifecycle
, Scheduled
, Warm
, Backup
, Backup
, Backup
, Compute
, Job
, Job
, Certificate
, Dns
, Private
, Slack
, Ec2
, Custom
, Edge
, Cache
, Cloud
, Distribution
, Function
, Key
, Origin
, Origin
, Public
, Response
, Trail
, Alarm
, Composite
, Dashboard
, Bit
, Git
, Git
, Pipeline
, Project
, Report
, Untrusted
, Repository
, Custom
, Ecs
, Lambda
, Lambda
, Server
, Server
, Server
, Profiling
, Pipeline
, Git
, Notification
, Identity
, Identity
, User
, User
, User
, User
, User
, User
, User
, User
, User
, Access
, Cloud
, Cloud
, Custom
, Managed
, Cluster
, Database
, Database
, Database
, Table
, Bastion
, Client
, Client
, Client
, Flow
, Gateway
, Instance
, Interface
, Launch
, Network
, Network
, Private
, Public
, Security
, Subnet
, Subnet
, Volume
, Vpc
, Vpc
, Vpn
, Vpn
, Repository
, Cluster
, Ec2
, Ec2
, External
, External
, Fargate
, Fargate
, Task
, Access
, File
, Cluster
, Cluster
, Fargate
, Nodegroup
, Open
, Load
, Application
, Application
, Network
, Network
, Domain
, Api
, Archive
, Connection
, Event
, Rule
, Lustre
, Accelerator
, Endpoint
, Listener
, Connection
, Database
, Job
, Security
, Table
, Access
, Group
, Lazy
, Managed
, Open
, Policy
, Role
, Saml
, User
, Topic
, Detector
, Input
, Channel
, Playback
, Stream
, Stream
, Application
, Delivery
, Alias
, Key
, Go
, Nodejs
, Python
, Python
, Alias
, Code
, Docker
, Event
, Event
, Function
, Function
, Layer
, Singleton
, Version
, Cross
, Log
, Log
, Metric
, Query
, Resource
, Subscription
, Cluster
, Cluster
, Database
, Database
, Parameter
, Subnet
, Domain
, Database
, Database
, Database
, Database
, Database
, Database
, Database
, Option
, Parameter
, Serverless
, Serverless
, Subnet
, Cluster
, Cluster
, Cluster
, Database
, ARecord
, Aaaa
, Caa
, Caa
, Cname
, Ds
, Hosted
, Mx
, Ns
, Private
, Public
, Record
, Srv
, Txt
, Zone
, Firewall
, Firewall
, Firewall
, Bucket
, Bucket
, Access
, Resource
, Rotation
, Secret
, Secret
, Cloud
, Portfolio
, Tag
, Application
, Attribute
, Alias
, Cname
, Http
, Ip
, Non
, Private
, Public
, Service
, Receipt
, Receipt
, Receipt
, Signing
, Subscription
, Topic
, Topic
, Queue
, Queue
, String
, String
, Activity
, State
, Canary
, Custom
, Aws
, Kubectl
, Node
, Trigger
A construct which represents an AWS resource.
Example
import * as cdk from '@aws-cdk/core';
class MyConstruct extends cdk.Resource implements cdk.ITaggable {
public readonly tags = new cdk.TagManager(cdk.TagType.KEY_VALUE, 'Whatever::The::Type');
constructor(scope: cdk.Construct, id: string) {
super(scope, id);
new cdk.CfnResource(this, 'Resource', {
type: 'Whatever::The::Type',
properties: {
// ...
Tags: this.tags.renderedTags,
},
});
}
}
Initializer
new Resource(scope: Construct, id: string, props?: ResourceProps)
Parameters
- scope
Construct
- id
string
- props
Resource
Props
Properties
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
node | Construct | The construct tree node associated with this construct. |
physical | string | Returns a string-encoded token that resolves to the physical name that should be passed to the CloudFormation resource. |
stack | Stack | The stack in which this resource is defined. |
env
Type:
Resource
The environment this resource belongs to.
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.
node
Type:
Construct
The construct tree node associated with this construct.
physicalName
Type:
string
Returns a string-encoded token that resolves to the physical name that should be passed to the CloudFormation resource.
This value will resolve to one of the following:
- a concrete value (e.g.
"my-awesome-bucket"
) undefined
, when a name should be generated by CloudFormation- a concrete name generated automatically during synthesis, in cross-environment scenarios.
stack
Type:
Stack
The stack in which this resource is defined.
Methods
Name | Description |
---|---|
apply | Apply the given removal policy to this resource. |
to | Returns a string representation of this construct. |
protected generate | |
protected get | Returns an environment-sensitive token that should be used for the resource's "ARN" attribute (e.g. bucket.bucketArn ). |
protected get | Returns an environment-sensitive token that should be used for the resource's "name" attribute (e.g. bucket.bucketName ). |
static is | Check whether the given construct is a Resource. |
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
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
).
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.
PhysicalName()
protected generateprotected generatePhysicalName(): string
Returns
string
ResourceArnAttribute(arnAttr, arnComponents)
protected getprotected getResourceArnAttribute(arnAttr: string, arnComponents: ArnComponents): string
Parameters
- arnAttr
string
— The CFN attribute which resolves to the ARN of the resource. - arnComponents
Arn
— The format of the ARN of this resource.Components
Returns
string
Returns an environment-sensitive token that should be used for the resource's "ARN" attribute (e.g. bucket.bucketArn
).
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
.
ResourceNameAttribute(nameAttr)
protected getprotected getResourceNameAttribute(nameAttr: string): string
Parameters
- nameAttr
string
— The CFN attribute which resolves to the resource's name.
Returns
string
Returns an environment-sensitive token that should be used for the resource's "name" attribute (e.g. bucket.bucketName
).
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.
Resource(construct)
static ispublic static isResource(construct: IConstruct): boolean
Parameters
- construct
IConstruct
Returns
boolean
Check whether the given construct is a Resource.