Registry / aws / aws-cdk-custom-resources

aws-cdk-custom-resources

JSON →
library1.204.0pypypi✓ verified 35d ago

The `aws-cdk-custom-resources` library, currently at version `1.204.0`, provides constructs within the AWS Cloud Development Kit (CDK) for implementing custom resources in CloudFormation. These resources extend CloudFormation capabilities by integrating with other AWS services or even third-party APIs. This package is part of the CDK v1 ecosystem, which is now in maintenance mode, receiving only critical updates. Users are encouraged to migrate to AWS CDK v2 for new development.

awsdevops
Install & Compatibility
Where this runs
tested against v1.204.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 56.5MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 7.1s · import 0.000s · 57MB
58MB installed
● package 58MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Common misspelling of the module path.

from aws_cdk.custom_resources import AwsCustomResource
from aws_cdk.custom_resources import AwsCustomResourcePolicy
from aws_cdk.custom_resources import PhysicalResourceId

Used for Lambda-backed custom resources where you provide the provider function.

from aws_cdk.custom_resources import CustomResource

This quickstart demonstrates how to use `AwsCustomResource` to make a direct AWS SDK call (listing objects in an S3 bucket) from a CDK stack. This construct simplifies interaction with AWS APIs that don't have direct CloudFormation support. Remember that `aws-cdk-custom-resources` is a V1 package.

import os from aws_cdk import ( Stack, App, Duration, ) from aws_cdk.aws_s3 import Bucket from aws_cdk.custom_resources import ( AwsCustomResource, AwsCustomResourcePolicy, PhysicalResourceId, ) from constructs import Construct class MyCustomResourceStack(Stack): def __init__(self, scope: Construct, id: str, **kwargs) -> None: super().__init__(scope, id, **kwargs) # Create an S3 bucket to interact with bucket = Bucket(self, "MyCustomResourceBucket") # Use AwsCustomResource to call S3 listObjectsV2 API # This construct makes direct SDK calls from CloudFormation s3_list_caller = AwsCustomResource( self, "S3ListCaller", on_create={ "service": "S3", "action": "listObjectsV2", "parameters": { "Bucket": bucket.bucket_name, }, "physical_resource_id": PhysicalResourceId.of(f"my-s3-lister-{bucket.bucket_name}"), }, on_update={ "service": "S3", "action": "listObjectsV2", "parameters": { "Bucket": bucket.bucket_name, }, "physical_resource_id": PhysicalResourceId.of(f"my-s3-lister-{bucket.bucket_name}"), }, # on_delete is optional; here it's not needed for a read-only action # For resources that create external entities, on_delete is critical for cleanup. policy=AwsCustomResourcePolicy.from_sdk_calls( resources=[bucket.bucket_arn, bucket.bucket_arn + "/*"] ), timeout=Duration.minutes(2) ) # You can retrieve outputs from the SDK call result # For listObjectsV2, it returns a list of contents. Here, we just get the Request ID. request_id = s3_list_caller.get_response_field("ResponseMetadata.RequestId") # In a real application, you might use this output, e.g., CfnOutput(self, "RequestId", value=request_id) app = App() MyCustomResourceStack(app, "MyCustomResourceExampleStack") app.synth()
Debug
Known footguns
breakingThis package is part of AWS CDK v1, which is in maintenance mode and no longer receives new features. While the `aws_cdk.custom_resources` module exists in CDK v2, using this V1 package (`aws-cdk-custom-resources`) alongside a CDK v2 project can lead to dependency conflicts and unexpected behavior due to different core libraries and versioning strategies.
gotchaCustom Resources, especially `AwsCustomResource`, require careful IAM permissions. If the underlying SDK call fails due to insufficient permissions, CloudFormation deployment will often fail with a generic 'Custom Resource failed' message, and details are only found in CloudWatch logs.
gotchaEnsuring a stable and unique `PhysicalResourceId` is crucial for custom resources, particularly for `on_update` and `on_delete` operations. A changing `PhysicalResourceId` or one that is not unique across deployments can lead to resource abandonment, orphaned resources, or unintended side effects during updates or rollbacks.
gotchaLambda-backed custom resources (using `CustomResource` with a `provider`) must return a specific JSON response format to CloudFormation within the specified timeout. Incorrect formats or exceeding the timeout will cause the CloudFormation deployment to fail.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
18 hits · last 30 days
gptbot
4
ahrefsbot
4
googlebot
4
script
1
bytedance
1
Resources