class CustomResourceProvider (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.CustomResourceProvider |
Java | software.amazon.awscdk.core.CustomResourceProvider |
Python | aws_cdk.core.CustomResourceProvider |
TypeScript (source) | @aws-cdk/core » CustomResourceProvider |
Implements
IConstruct
, IConstruct
, IDependable
An AWS-Lambda backed custom resource provider, for CDK Construct Library constructs.
This is a provider for CustomResource
constructs, backed by an AWS Lambda
Function. It only supports NodeJS runtimes.
This is not a generic custom resource provider class. It is specifically
intended to be used only by constructs in the AWS CDK Construct Library, and
only exists here because of reverse dependency issues (for example, it cannot
use iam.PolicyStatement
objects, since the iam
library already depends on
the CDK core
library and we cannot have cyclic dependencies).
If you are not writing constructs for the AWS Construct Library, you should
use the Provider
class in the custom-resources
module instead, which has
a better API and supports all Lambda runtimes, not just Node.
N.B.: When you are writing Custom Resource Providers, there are a number of
lifecycle events you have to pay attention to. These are documented in the
README of the custom-resources
module. Be sure to give the documentation
in that module a read, regardless of whether you end up using the Provider
class in there or this one.
Example
const provider = CustomResourceProvider.getOrCreateProvider(this, 'Custom::MyCustomResourceType', {
codeDirectory: `${__dirname}/my-handler`,
runtime: CustomResourceProviderRuntime.NODEJS_14_X,
});
const roleArn = provider.roleArn;
Initializer (protected)
super(scope: Construct, id: string, props: CustomResourceProviderProps)
Parameters
- scope
Construct
- id
string
- props
Custom
Resource Provider Props
Construct Props
Name | Type | Description |
---|---|---|
code | string | A local file system directory with the provider's code. |
runtime | Custom | The AWS Lambda runtime and version to use for the provider. |
description? | string | A description of the function. |
environment? | { [string]: string } | Key-value pairs that are passed to Lambda as Environment. |
memory | Size | The amount of memory that your function has access to. |
policy | any[] | A set of IAM policy statements to include in the inline policy of the provider's lambda function. |
timeout? | Duration | AWS Lambda timeout for the provider. |
codeDirectory
Type:
string
A local file system directory with the provider's code.
The code will be bundled into a zip asset and wired to the provider's AWS Lambda function.
runtime
Type:
Custom
The AWS Lambda runtime and version to use for the provider.
description?
Type:
string
(optional, default: No description.)
A description of the function.
environment?
Type:
{ [string]: string }
(optional, default: No environment variables.)
Key-value pairs that are passed to Lambda as Environment.
memorySize?
Type:
Size
(optional, default: Size.mebibytes(128))
The amount of memory that your function has access to.
Increasing the function's memory also increases its CPU allocation.
policyStatements?
Type:
any[]
(optional, default: no additional inline policy)
A set of IAM policy statements to include in the inline policy of the provider's lambda function.
Please note: these are direct IAM JSON policy blobs, not iam.PolicyStatement
objects like you will see in the rest of the CDK.
Example
const provider = CustomResourceProvider.getOrCreateProvider(this, 'Custom::MyCustomResourceType', {
codeDirectory: `${__dirname}/my-handler`,
runtime: CustomResourceProviderRuntime.NODEJS_14_X,
policyStatements: [
{
Effect: 'Allow',
Action: 's3:PutObject*',
Resource: '*',
}
],
});
timeout?
Type:
Duration
(optional, default: Duration.minutes(15))
AWS Lambda timeout for the provider.
Properties
Name | Type | Description |
---|---|---|
code | string | The hash of the lambda code backing this provider. |
node | Construct | The construct tree node associated with this construct. |
role | string | The ARN of the provider's AWS Lambda function role. |
service | string | The ARN of the provider's AWS Lambda function which should be used as the serviceToken when defining a custom resource. |
codeHash
Type:
string
The hash of the lambda code backing this provider.
Can be used to trigger updates on code changes, even when the properties of a custom resource remain unchanged.
node
Type:
Construct
The construct tree node associated with this construct.
roleArn
Type:
string
The ARN of the provider's AWS Lambda function role.
serviceToken
Type:
string
The ARN of the provider's AWS Lambda function which should be used as the serviceToken
when defining a custom resource.
Example
declare const myProvider: CustomResourceProvider;
new CustomResource(this, 'MyCustomResource', {
serviceToken: myProvider.serviceToken,
properties: {
myPropertyOne: 'one',
myPropertyTwo: 'two',
},
});
Methods
Name | Description |
---|---|
to | Returns a string representation of this construct. |
static get | Returns a stack-level singleton ARN (service token) for the custom resource provider. |
static get | Returns a stack-level singleton for the custom resource provider. |
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.
OrCreate(scope, uniqueid, props)
static getpublic static getOrCreate(scope: Construct, uniqueid: string, props: CustomResourceProviderProps): string
Parameters
- scope
Construct
— Construct scope. - uniqueid
string
— A globally unique id that will be used for the stack-level construct. - props
Custom
— Provider properties which will only be applied when the provider is first created.Resource Provider Props
Returns
string
Returns a stack-level singleton ARN (service token) for the custom resource provider.
OrCreateProvider(scope, uniqueid, props)
static getpublic static getOrCreateProvider(scope: Construct, uniqueid: string, props: CustomResourceProviderProps): CustomResourceProvider
Parameters
- scope
Construct
— Construct scope. - uniqueid
string
— A globally unique id that will be used for the stack-level construct. - props
Custom
— Provider properties which will only be applied when the provider is first created.Resource Provider Props
Returns
Returns a stack-level singleton for the custom resource provider.