AwsCustomResource

class aws_cdk.custom_resources.AwsCustomResource(scope, id, *, policy, log_retention=None, on_create=None, on_delete=None, on_update=None, resource_type=None, role=None, timeout=None)

Bases: aws_cdk.core.Construct

Defines a custom resource that is materialized using specific AWS API calls.

Use this to bridge any gap that might exist in the CloudFormation Coverage. You can specify exactly which calls are invoked for the ‘CREATE’, ‘UPDATE’ and ‘DELETE’ life cycle events.

__init__(scope, id, *, policy, log_retention=None, on_create=None, on_delete=None, on_update=None, resource_type=None, role=None, timeout=None)
Parameters
  • scope (Construct) –

  • id (str) –

  • policy (AwsCustomResourcePolicy) – The policy that will be added to the execution role of the Lambda function implementing this custom resource provider. The custom resource also implements iam.IGrantable, making it possible to use the grantXxx() methods. As this custom resource uses a singleton Lambda function, it’s important to note the that function’s role will eventually accumulate the permissions/grants from all resources.

  • log_retention (Optional[RetentionDays]) – The number of days log events of the Lambda function implementing this custom resource are kept in CloudWatch Logs. Default: logs.RetentionDays.INFINITE

  • on_create (Optional[AwsSdkCall]) – The AWS SDK call to make when the resource is created. Default: - the call when the resource is updated

  • on_delete (Optional[AwsSdkCall]) – The AWS SDK call to make when the resource is deleted. Default: - no call

  • on_update (Optional[AwsSdkCall]) – The AWS SDK call to make when the resource is updated. Default: - no call

  • resource_type (Optional[str]) – Cloudformation Resource type. Default: - Custom::AWS

  • role (Optional[IRole]) – The execution role for the Lambda function implementing this custom resource provider. This role will apply to all AwsCustomResource instances in the stack. The role must be assumable by the lambda.amazonaws.com service principal. Default: - a new role is created

  • timeout (Optional[Duration]) – The timeout for the Lambda function implementing this custom resource. Default: Duration.minutes(2)

Return type

None

Methods

get_response_field(data_path)

Returns response data for the AWS SDK call as string.

Example for S3 / listBucket : ‘Buckets.0.Name’

Note that you cannot use this method if ignoreErrorCodesMatching is configured for any of the SDK calls. This is because in such a case, the response data might not exist, and will cause a CloudFormation deploy time error.

Parameters

data_path (str) – the path to the data.

Return type

str

get_response_field_reference(data_path)

Returns response data for the AWS SDK call.

Example for S3 / listBucket : ‘Buckets.0.Name’

Use Token.asXxx to encode the returned Reference as a specific type or use the convenience getDataString for string attributes.

Note that you cannot use this method if ignoreErrorCodesMatching is configured for any of the SDK calls. This is because in such a case, the response data might not exist, and will cause a CloudFormation deploy time error.

Parameters

data_path (str) – the path to the data.

Return type

Reference

to_string()

Returns a string representation of this construct.

Return type

str

Attributes

grant_principal

The principal to grant permissions to.

Return type

IPrincipal

node

The construct tree node associated with this construct.

Return type

ConstructNode

Static Methods

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters

x (Any) –

Return type

bool