Skip to main content

CDK Constructs for AWS CloudFormation

Project description

AWS CloudFormation Construct Library


Stability: Stable


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

Custom Resources

Custom Resources are CloudFormation resources that are implemented by arbitrary user code. They can do arbitrary lookups or modifications during a CloudFormation synthesis run.

You will typically use Lambda to implement a Construct implemented as a Custom Resource (though SNS topics can be used as well). Your Lambda function will be sent a CREATE, UPDATE or DELETE message, depending on the CloudFormation life cycle. It will perform whatever actions it needs to, and then return any number of output values which will be available as attributes of your Construct. In turn, those can be used as input to other Constructs in your model.

In general, consumers of your Construct will not need to care whether it is implemented in term of other CloudFormation resources or as a custom resource.

Note: when implementing your Custom Resource using a Lambda, use a SingletonLambda so that even if your custom resource is instantiated multiple times, the Lambda will only get uploaded once.

Example

The following shows an example of a declaring Custom Resource that copies files into an S3 bucket during deployment (the implementation of the actual Lambda handler is elided for brevity).

interface CopyOperationProps {
  sourceBucket: IBucket;
  targetBucket: IBucket;
}

class CopyOperation extends Construct {
  constructor(parent: Construct, name: string, props: CopyOperationProps) {
    super(parent, name);

    const lambdaProvider = new lambda.SingletonFunction(this, 'Provider', {
      uuid: 'f7d4f730-4ee1-11e8-9c2d-fa7ae01bbebc',
      runtime: lambda.Runtime.PYTHON_3_7,
      code: lambda.Code.fromAsset('../copy-handler'),
      handler: 'index.handler',
      timeout: Duration.seconds(60),
    });

    new CustomResource(this, 'Resource', {
      provider: CustomResourceProvider.lambda(lambdaProvider),
      properties: {
        sourceBucketArn: props.sourceBucket.bucketArn,
        targetBucketArn: props.targetBucket.bucketArn,
      }
    });
  }
}

The aws-cdk-examples repository has examples for adding custom resources.

References

See the following section of the docs on details to write Custom Resources:

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.aws-cloudformation-1.6.0.tar.gz (52.3 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.aws_cloudformation-1.6.0-py3-none-any.whl (49.5 kB view details)

Uploaded Python 3

File details

Details for the file aws-cdk.aws-cloudformation-1.6.0.tar.gz.

File metadata

  • Download URL: aws-cdk.aws-cloudformation-1.6.0.tar.gz
  • Upload date:
  • Size: 52.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.5

File hashes

Hashes for aws-cdk.aws-cloudformation-1.6.0.tar.gz
Algorithm Hash digest
SHA256 5c002c4d07ae0bc4d297141e185de3e5686977d89898d39a6d6ac229f7a2dd34
MD5 a6802e5ac8bf45c50911bf3e513c5684
BLAKE2b-256 42d7adcd9afaebfbaf898ae480f99d7b592bd180057a491e1ec8d044da46af72

See more details on using hashes here.

File details

Details for the file aws_cdk.aws_cloudformation-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: aws_cdk.aws_cloudformation-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 49.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.5

File hashes

Hashes for aws_cdk.aws_cloudformation-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9168de21c154c79504eab67fad36a8a910189169e422902c8f09387fa4ad8c42
MD5 8d587ff2c8fe6c74d44b6fe92c9c05f3
BLAKE2b-256 2cfa57d63ec7db45a2f0a464b97edd39377a7647f6f8a8c9ad82111c68bf3e1e

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