Skip to main content

cdk-triggers

Project description

CDK Triggers

Under Construction

We are building this as part of the CDK Construction Zone Twitch series on twitch.tv/aws. To Follow up, subscribe to the RFC issue on GitHub.


The APIs of higher level constructs in this module are experimental and under active development. They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and breaking changes will be announced in the release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.

Overview

Allow specifying arbitrary handlers which execute as part of the deployment process and trigger them before/after resources or stacks.

Usage

Hypothetical README

You can trigger the execution of arbitrary AWS Lambda functions before or after resources or groups of resources are provisioned using the Triggers API.

The library includes constructs that represent different triggers. The BeforeCreate and AfterCreate constructs can be used to trigger a handler before/after a set of resources have been created.

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
triggers.AfterCreate(self, "InvokeAfter",
    resources=[resource1, resource2, stack, ...],
    handler=my_lambda_function
)

Similarly, triggers.BeforeCreate can be used to set up a "before" trigger.

Where resources is a list of construct scopes which determine when handler is invoked. Scopes can be either specific resources or composite constructs (in which case all the resources in the construct will be used as a group). The scope can also be a Stack, in which case the trigger will apply to all the resources within the stack (same as any composite construct). All scopes must roll up to the same stack.

Let's look at an example. Say we want to publish a notification to an SNS topic that says "hello, topic!" after the topic is created.

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
# define a topic
topic = sns.Topic(self, "MyTopic")

# define a lambda function which publishes a message to the topic
publisher = NodeJsFunction(self, "PublishToTopic")
publisher.add_environment("TOPIC_ARN", topic.topic_arn)
publisher.add_environment("MESSAGE", "Hello, topic!")
topic.grant_publish(publisher)

# trigger the lambda function after the topic is created
triggers.AfterCreate(self, "SayHello",
    scopes=[topic],
    handler=publisher
)

Requirements

  • One-off exec before/after resource/s are created (Trigger.AfterCreate).
  • Additional periodic execution after deployment (repeatOnSchedule).
  • Async checks (retryWithTImeout)
  • Execute on updates (bind logical ID to hash of CFN properties of triggered resource)
  • Execute shell command inside a Docker image

Use Cases

Here are some examples of use cases for triggers:

  • Intrinsic validations: execute a check to verify that a resource or set of resources have been deployed correctly

    • Test connections to external systems (e.g. security tokens are valid)
    • Verify integration between resources is working as expected
    • Execute as one-off and also periodically after deployment
    • Wait for data to start flowing (e.g. wait for a metric) before deployment is successful
  • Data priming: add data to resources after they are created

    • CodeCommit repo + initial commit
    • Database + test data for development
  • Check prerequisites before depoyment

    • Account limits
    • Availability of external services
  • Connect to other accounts

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

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

cdk-triggers-0.0.62.tar.gz (27.6 kB view details)

Uploaded Source

Built Distribution

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

cdk_triggers-0.0.62-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

Details for the file cdk-triggers-0.0.62.tar.gz.

File metadata

  • Download URL: cdk-triggers-0.0.62.tar.gz
  • Upload date:
  • Size: 27.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.10

File hashes

Hashes for cdk-triggers-0.0.62.tar.gz
Algorithm Hash digest
SHA256 3ff45e562551e1186f61b248d158e0c45c1b217f314f71582a5c9670b29dab48
MD5 da4f10abc86ab86bf9a90fc7b387f151
BLAKE2b-256 7706729a5a64672bbe3e641afcdb0711ee4cf0f9a9d5810ef7fd7d4606b8f70e

See more details on using hashes here.

File details

Details for the file cdk_triggers-0.0.62-py3-none-any.whl.

File metadata

  • Download URL: cdk_triggers-0.0.62-py3-none-any.whl
  • Upload date:
  • Size: 28.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.10

File hashes

Hashes for cdk_triggers-0.0.62-py3-none-any.whl
Algorithm Hash digest
SHA256 7361710f6e17c721e36a82d530792cce6abc985f2580fed630e24bb7cfab9065
MD5 ff9a221fe0356e52ce0e58d46159b908
BLAKE2b-256 529eb198ff35bf5ce473c1668fc86e176356b5e8e5f661bb8bbfd4089c8fa987

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