class CustomResource (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.CloudFormation.CustomResource |
Java | software.amazon.awscdk.services.cloudformation.CustomResource |
Python | aws_cdk.aws_cloudformation.CustomResource |
TypeScript (source) | @aws-cdk/aws-cloudformation » CustomResource |
⚠️ Deprecated: use core.CustomResource
Implements
IConstruct
, IConstruct
, IDependable
, IResource
Deprecated.
Example
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cloudformation from '@aws-cdk/aws-cloudformation';
import * as cdk from '@aws-cdk/core';
declare const customResourceProvider: cloudformation.CustomResourceProvider;
declare const properties: any;
const customResource = new cloudformation.CustomResource(this, 'MyCustomResource', {
provider: customResourceProvider,
// the properties below are optional
properties: {
propertiesKey: properties,
},
removalPolicy: cdk.RemovalPolicy.DESTROY,
resourceType: 'resourceType',
});
Initializer
new CustomResource(scope: Construct, id: string, props: CustomResourceProps)
⚠️ Deprecated: use core.CustomResource
Parameters
- scope
Construct
- id
string
- props
Custom
Resource Props
Construct Props
Name | Type | Description |
---|---|---|
provider | ICustom | The provider which implements the custom resource. |
properties? | { [string]: any } | Properties to pass to the Lambda. |
removal | Removal | The policy to apply when this resource is removed from the application. |
resource | string | For custom resources, you can specify AWS::CloudFormation::CustomResource (the default) as the resource type, or you can specify your own resource type name. |
provider
⚠️ Deprecated: use core.CustomResourceProps
Type:
ICustom
The provider which implements the custom resource.
You can implement a provider by listening to raw AWS CloudFormation events through an SNS topic or an AWS Lambda function or use the CDK's custom resource provider framework which makes it easier to implement robust providers.
import * as custom_resources from '@aws-cdk/custom-resources';
import * as lambda from '@aws-cdk/aws-lambda';
import { Stack } from '@aws-cdk/core';
declare const myOnEventLambda: lambda.Function;
declare const myIsCompleteLambda: lambda.Function;
const stack = new Stack();
const provider = new custom_resources.Provider(stack, 'myProvider', {
onEventHandler: myOnEventLambda,
isCompleteHandler: myIsCompleteLambda, // optional
});
import * as cloudformation from '@aws-cdk/aws-cloudformation';
import * as lambda from '@aws-cdk/aws-lambda';
declare const myFunction: lambda.Function;
// invoke an AWS Lambda function when a lifecycle event occurs:
const provider = cloudformation.CustomResourceProvider.fromLambda(myFunction);
import * as cloudformation from '@aws-cdk/aws-cloudformation';
import * as sns from '@aws-cdk/aws-sns';
declare const myTopic: sns.Topic;
// publish lifecycle events to an SNS topic:
const provider = cloudformation.CustomResourceProvider.fromTopic(myTopic);
properties?
⚠️ Deprecated: use core.CustomResourceProps
Type:
{ [string]: any }
(optional, default: No properties.)
Properties to pass to the Lambda.
removalPolicy?
⚠️ Deprecated: use core.CustomResourceProps
Type:
Removal
(optional, default: cdk.RemovalPolicy.Destroy)
The policy to apply when this resource is removed from the application.
resourceType?
⚠️ Deprecated: use core.CustomResourceProps
Type:
string
(optional, default: AWS::CloudFormation::CustomResource)
For custom resources, you can specify AWS::CloudFormation::CustomResource (the default) as the resource type, or you can specify your own resource type name.
For example, you can use "Custom::MyCustomResourceTypeName".
Custom resource type names must begin with "Custom::" and can include alphanumeric characters and the following characters: _@-. You can specify a custom resource type name up to a maximum length of 60 characters. You cannot change the type during an update.
Using your own resource type names helps you quickly differentiate the types of custom resources in your stack. For example, if you had two custom resources that conduct two different ping tests, you could name their type as Custom::PingTester to make them easily identifiable as ping testers (instead of using AWS::CloudFormation::CustomResource).
Properties
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
node | Construct | The construct tree node associated with this construct. |
ref | string | The physical name of this custom resource. |
stack | Stack | The stack in which this resource is defined. |
env
⚠️ Deprecated: use core.CustomResource
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
⚠️ Deprecated: use core.CustomResource
Type:
Construct
The construct tree node associated with this construct.
ref
⚠️ Deprecated: use core.CustomResource
Type:
string
The physical name of this custom resource.
stack
⚠️ Deprecated: use core.CustomResource
Type:
Stack
The stack in which this resource is defined.
Methods
Name | Description |
---|---|
apply | Apply the given removal policy to this resource. |
get | Returns the value of an attribute of the custom resource of an arbitrary type. |
get | Returns the value of an attribute of the custom resource of type string. |
to | Returns a string representation of this construct. |
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
⚠️ Deprecated: use core.CustomResource
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
).
Att(attributeName)
getpublic getAtt(attributeName: string): Reference
⚠️ Deprecated: use core.CustomResource
Parameters
- attributeName
string
— the name of the attribute.
Returns
Returns the value of an attribute of the custom resource of an arbitrary type.
Attributes are returned from the custom resource provider through the
Data
map where the key is the attribute name.
AttString(attributeName)
getpublic getAttString(attributeName: string): string
⚠️ Deprecated: use core.CustomResource
Parameters
- attributeName
string
— the name of the attribute.
Returns
string
Returns the value of an attribute of the custom resource of type string.
Attributes are returned from the custom resource provider through the
Data
map where the key is the attribute name.
String()
topublic toString(): string
⚠️ Deprecated: use core.CustomResource
Returns
string
Returns a string representation of this construct.