Registry /
aws / aws-cdk-custom-resources
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.
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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 56.5MB
glibcpy 3.10–3.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()
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.