# CDK Triggers
> 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](https://semver.org/) 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
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.
```python
# Example automatically generated from non-compiling source. May contain errors.
triggers.AfterCreate(self, "InvokeAfter",
resources=[resource1, resource2, stack, ...],
handler=my_lambda_function
)
```
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.
```python
# Example automatically generated from non-compiling source. May contain errors.
# 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
)
```
## Additional Notes
* If the trigger fails, deployment fails.
* If the handler changes (configuration or code), the trigger gets re-executed (trigger is bound to `lambda.currentVersion` which gets recreated
when the function changes).
## Roadmap
* Additional periodic execution after deployment (`repeatOnSchedule`).
* Async checks (`retryWithTimeout`)
* 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](CONTRIBUTING.md#security-issue-notifications) for more information.
## License
This project is licensed under the Apache-2.0 License.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
资源分类:Python库 所属语言:Python 资源全名:cdk-triggers-0.0.172.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
cdk-triggers-0.0.172.tar.gz (17个子文件)
cdk-triggers-0.0.172
MANIFEST.in 23B
PKG-INFO 4KB
NOTICE 67B
pyproject.toml 106B
LICENSE 11KB
src
cdk_triggers.egg-info
PKG-INFO 4KB
requires.txt 129B
SOURCES.txt 402B
top_level.txt 13B
dependency_links.txt 1B
cdk_triggers
py.typed 1B
_jsii
cdk-triggers@0.0.172.jsii.tgz 16KB
__init__.py 398B
__init__.py 7KB
setup.cfg 38B
setup.py 2KB
README.md 4KB
共 17 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功