Skip to main content

Constructs for implementing CDK custom resources

Project description

CDK Custom Resources

---

Stability: Experimental

This is a developer preview (public beta) module. Releases might lack important features and might have future breaking changes.

This API is still under active development and subject to non-backward compatible changes or removal in any future version. Use of the API is not recommended in production environments. Experimental APIs are not subject to the Semantic Versioning model.


This module is part of the AWS Cloud Development Kit project.

AWS Custom Resource

Sometimes a single API call can fill the gap in the CloudFormation coverage. In this case you can use the AwsCustomResource construct. This construct creates a custom resource that can be customized to make specific API calls for the CREATE, UPDATE and DELETE events. Additionally, data returned by the API call can be extracted and used in other constructs/resources (creating a real CloudFormation dependency using Fn::GetAtt under the hood).

The physical id of the custom resource can be specified or derived from the data returned by the API call.

The AwsCustomResource uses the AWS SDK for JavaScript. Services, actions and parameters can be found in the API documentation.

Path to data must be specified using a dot notation, e.g. to get the string value of the Title attribute for the first item returned by dynamodb.query it should be Items.0.Title.S.

Examples

Verify a domain with SES:

# Example may have issues. See https://github.com/aws/jsii/issues/826
verify_domain_identity = AwsCustomResource(self, "VerifyDomainIdentity",
    on_create={
        "service": "SES",
        "action": "verifyDomainIdentity",
        "parameters": {
            "Domain": "example.com"
        },
        "physical_resource_id_path": "VerificationToken"
    }
)

route53.TxtRecord(zone, "SESVerificationRecord",
    record_name="_amazonses.example.com",
    record_value=verify_domain_identity.get_data("VerificationToken")
)

Get the latest version of a secure SSM parameter:

# Example may have issues. See https://github.com/aws/jsii/issues/826
get_parameter = AwsCustomResource(self, "GetParameter",
    on_update={# will also be called for a CREATE event
        "service": "SSM",
        "action": "getParameter",
        "parameters": {
            "Name": "my-parameter",
            "WithDecryption": True
        },
        "physical_resource_id": Date.now().to_string()}
)

# Use the value in another construct with
get_parameter.get_data("Parameter.Value")

IAM policy statements required to make the API calls are derived from the calls and allow by default the actions to be made on all resources (*). You can restrict the permissions by specifying your own list of statements with the policyStatements prop.

Chained API calls can be achieved by creating dependencies:

# Example may have issues. See https://github.com/aws/jsii/issues/826
aws_custom1 = AwsCustomResource(self, "API1",
    on_create={
        "service": "...",
        "action": "...",
        "physical_resource_id": "..."
    }
)

aws_custom2 = AwsCustomResource(self, "API2",
    on_create={
        "service": "...",
        "action": "...",
        "parameters": {
            "text": aws_custom1.get_data("Items.0.text")
        },
        "physical_resource_id": "..."
    }
)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws-cdk.custom-resources-1.14.0.tar.gz (47.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aws_cdk.custom_resources-1.14.0-py3-none-any.whl (45.2 kB view details)

Uploaded Python 3

File details

Details for the file aws-cdk.custom-resources-1.14.0.tar.gz.

File metadata

  • Download URL: aws-cdk.custom-resources-1.14.0.tar.gz
  • Upload date:
  • Size: 47.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.5

File hashes

Hashes for aws-cdk.custom-resources-1.14.0.tar.gz
Algorithm Hash digest
SHA256 145e169b1dd886b91607f5c43c923b5169c4e710dc08341d9e54e6b4b67b893b
MD5 43e79f86ebdc132023eb870f61f6c087
BLAKE2b-256 887317b2871ee4fcafdf06645110b857d937683b08096e11760b27c79ae960e8

See more details on using hashes here.

File details

Details for the file aws_cdk.custom_resources-1.14.0-py3-none-any.whl.

File metadata

  • Download URL: aws_cdk.custom_resources-1.14.0-py3-none-any.whl
  • Upload date:
  • Size: 45.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.5

File hashes

Hashes for aws_cdk.custom_resources-1.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9e1477a9391a6a093cf1b3826d5d6975c0c89aa735cf3db3dd3ac980bea4add
MD5 ad00ff03d201ebd717fd52f2a66c59e3
BLAKE2b-256 51ababc26b2ce6a550de8e35001fa027987a3497c147ecee0afb3daa7b142952

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page