aws-cdk.triggers


Nameaws-cdk.triggers JSON
Version 1.204.0 PyPI version JSON
download
home_pagehttps://github.com/aws/aws-cdk
SummaryExecute AWS Lambda functions during deployment
upload_time2023-06-19 21:08:33
maintainer
docs_urlNone
authorAmazon Web Services
requires_python~=3.7
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Triggers

<!--BEGIN STABILITY BANNER-->---


![End-of-Support](https://img.shields.io/badge/End--of--Support-critical.svg?style=for-the-badge)

> AWS CDK v1 has reached End-of-Support on 2023-06-01.
> This package is no longer being updated, and users should migrate to AWS CDK v2.
>
> For more information on how to migrate, see the [*Migrating to AWS CDK v2* guide](https://docs.aws.amazon.com/cdk/v2/guide/migrating-v2.html).

---
<!--END STABILITY BANNER-->

Triggers allows you to execute code during deployments. This can be used for a
variety of use cases such as:

* Self tests: validate something after a resource/construct been provisioned
* Data priming: add initial data to resources after they are created
* Preconditions: check things such as account limits or external dependencies
  before deployment.

## Usage

The `TriggerFunction` construct will define an AWS Lambda function which is
triggered *during* deployment:

```python
import aws_cdk.aws_lambda as lambda_
import aws_cdk.triggers as triggers
from aws_cdk.core import Stack

# stack: Stack

triggers.TriggerFunction(stack, "MyTrigger",
    runtime=lambda_.Runtime.NODEJS_14_X,
    handler="index.handler",
    code=lambda_.Code.from_asset(__dirname + "/my-trigger")
)
```

In the above example, the AWS Lambda function defined in `myLambdaFunction` will
be invoked when the stack is deployed.

## Trigger Failures

If the trigger handler fails (e.g. an exception is raised), the CloudFormation
deployment will fail, as if a resource failed to provision. This makes it easy
to implement "self tests" via triggers by simply making a set of assertions on
some provisioned infrastructure.

## Order of Execution

By default, a trigger will be executed by CloudFormation after the associated
handler is provisioned. This means that if the handler takes an implicit
dependency on other resources (e.g. via environment variables), those resources
will be provisioned *before* the trigger is executed.

In most cases, implicit ordering should be sufficient, but you can also use
`executeAfter` and `executeBefore` to control the order of execution.

The following example defines the following order: `(hello, world) => myTrigger => goodbye`.
The resources under `hello` and `world` will be provisioned in
parallel, and then the trigger `myTrigger` will be executed. Only then the
resources under `goodbye` will be provisioned:

```python
from constructs import Construct, Node
import aws_cdk.triggers as triggers

# my_trigger: triggers.Trigger
# hello: Construct
# world: Construct
# goodbye: Construct

my_trigger.execute_after(hello, world)
my_trigger.execute_before(goodbye)
```

Note that `hello` and `world` are construct *scopes*. This means that they can
be specific resources (such as an `s3.Bucket` object) or groups of resources
composed together into constructs.

## Re-execution of Triggers

By default, `executeOnHandlerChange` is enabled. This implies that the trigger
is re-executed every time the handler function code or configuration changes. If
this option is disabled, the trigger will be executed only once upon first
deployment.

In the future we will consider adding support for additional re-execution modes:

* `executeOnEveryDeployment: boolean` - re-executes every time the stack is
  deployed (add random "salt" during synthesis).
* `executeOnResourceChange: Construct[]` - re-executes when one of the resources
  under the specified scopes has changed (add the hash the CloudFormation
  resource specs).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aws/aws-cdk",
    "name": "aws-cdk.triggers",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "~=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Amazon Web Services",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/bf/e8/a83f039673f4f0a2b7c6ef2e484a63d9568e7fc5d9d7284e67313d9cf54b/aws-cdk.triggers-1.204.0.tar.gz",
    "platform": null,
    "description": "# Triggers\n\n<!--BEGIN STABILITY BANNER-->---\n\n\n![End-of-Support](https://img.shields.io/badge/End--of--Support-critical.svg?style=for-the-badge)\n\n> AWS CDK v1 has reached End-of-Support on 2023-06-01.\n> This package is no longer being updated, and users should migrate to AWS CDK v2.\n>\n> For more information on how to migrate, see the [*Migrating to AWS CDK v2* guide](https://docs.aws.amazon.com/cdk/v2/guide/migrating-v2.html).\n\n---\n<!--END STABILITY BANNER-->\n\nTriggers allows you to execute code during deployments. This can be used for a\nvariety of use cases such as:\n\n* Self tests: validate something after a resource/construct been provisioned\n* Data priming: add initial data to resources after they are created\n* Preconditions: check things such as account limits or external dependencies\n  before deployment.\n\n## Usage\n\nThe `TriggerFunction` construct will define an AWS Lambda function which is\ntriggered *during* deployment:\n\n```python\nimport aws_cdk.aws_lambda as lambda_\nimport aws_cdk.triggers as triggers\nfrom aws_cdk.core import Stack\n\n# stack: Stack\n\ntriggers.TriggerFunction(stack, \"MyTrigger\",\n    runtime=lambda_.Runtime.NODEJS_14_X,\n    handler=\"index.handler\",\n    code=lambda_.Code.from_asset(__dirname + \"/my-trigger\")\n)\n```\n\nIn the above example, the AWS Lambda function defined in `myLambdaFunction` will\nbe invoked when the stack is deployed.\n\n## Trigger Failures\n\nIf the trigger handler fails (e.g. an exception is raised), the CloudFormation\ndeployment will fail, as if a resource failed to provision. This makes it easy\nto implement \"self tests\" via triggers by simply making a set of assertions on\nsome provisioned infrastructure.\n\n## Order of Execution\n\nBy default, a trigger will be executed by CloudFormation after the associated\nhandler is provisioned. This means that if the handler takes an implicit\ndependency on other resources (e.g. via environment variables), those resources\nwill be provisioned *before* the trigger is executed.\n\nIn most cases, implicit ordering should be sufficient, but you can also use\n`executeAfter` and `executeBefore` to control the order of execution.\n\nThe following example defines the following order: `(hello, world) => myTrigger => goodbye`.\nThe resources under `hello` and `world` will be provisioned in\nparallel, and then the trigger `myTrigger` will be executed. Only then the\nresources under `goodbye` will be provisioned:\n\n```python\nfrom constructs import Construct, Node\nimport aws_cdk.triggers as triggers\n\n# my_trigger: triggers.Trigger\n# hello: Construct\n# world: Construct\n# goodbye: Construct\n\nmy_trigger.execute_after(hello, world)\nmy_trigger.execute_before(goodbye)\n```\n\nNote that `hello` and `world` are construct *scopes*. This means that they can\nbe specific resources (such as an `s3.Bucket` object) or groups of resources\ncomposed together into constructs.\n\n## Re-execution of Triggers\n\nBy default, `executeOnHandlerChange` is enabled. This implies that the trigger\nis re-executed every time the handler function code or configuration changes. If\nthis option is disabled, the trigger will be executed only once upon first\ndeployment.\n\nIn the future we will consider adding support for additional re-execution modes:\n\n* `executeOnEveryDeployment: boolean` - re-executes every time the stack is\n  deployed (add random \"salt\" during synthesis).\n* `executeOnResourceChange: Construct[]` - re-executes when one of the resources\n  under the specified scopes has changed (add the hash the CloudFormation\n  resource specs).\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Execute AWS Lambda functions during deployment",
    "version": "1.204.0",
    "project_urls": {
        "Homepage": "https://github.com/aws/aws-cdk",
        "Source": "https://github.com/aws/aws-cdk.git"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "50e5c69ec07c4f248e83a16026707045414b86ef9a55e58e82feae1d87631bde",
                "md5": "046bdd98160cce96d87de71cc859fc50",
                "sha256": "811b299bea208e33a5a728fd8be2f1dce8214aac62f8aad0bf1377da2f6f2f3c"
            },
            "downloads": -1,
            "filename": "aws_cdk.triggers-1.204.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "046bdd98160cce96d87de71cc859fc50",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "~=3.7",
            "size": 52542,
            "upload_time": "2023-06-19T21:02:33",
            "upload_time_iso_8601": "2023-06-19T21:02:33.756800Z",
            "url": "https://files.pythonhosted.org/packages/50/e5/c69ec07c4f248e83a16026707045414b86ef9a55e58e82feae1d87631bde/aws_cdk.triggers-1.204.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bfe8a83f039673f4f0a2b7c6ef2e484a63d9568e7fc5d9d7284e67313d9cf54b",
                "md5": "256cd49e48c40454553db2716a8830b0",
                "sha256": "929d6aef6767711b05dfa5e07d33bac172a9fbb032bbae411f7e8f5b61bbfce1"
            },
            "downloads": -1,
            "filename": "aws-cdk.triggers-1.204.0.tar.gz",
            "has_sig": false,
            "md5_digest": "256cd49e48c40454553db2716a8830b0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "~=3.7",
            "size": 53726,
            "upload_time": "2023-06-19T21:08:33",
            "upload_time_iso_8601": "2023-06-19T21:08:33.728965Z",
            "url": "https://files.pythonhosted.org/packages/bf/e8/a83f039673f4f0a2b7c6ef2e484a63d9568e7fc5d9d7284e67313d9cf54b/aws-cdk.triggers-1.204.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-19 21:08:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aws",
    "github_project": "aws-cdk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "aws-cdk.triggers"
}
        
Elapsed time: 0.11931s