如何将新的 cdk 堆栈与现有的 aws EventBridge (EventTarget) 集成
How to integrate new cdk stack with existed aws EventBridge (EventTarget)
由于AWS上的资源是在控制台手动创建的。例如
Rule、EventBus、APIDestination(目标)。表示这些资源不提供任何cdk代码。
要点是我想用现有的 EventBus 和 APIDestination 添加更多 Rule(目标)**。然后自定义input_transformer in targets within cdk code.
from aws_cdk import aws_events as events, aws_events_targets as targets
class TheDestinedLambdaStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
new_rule = events.Rule(
self,
"rule",
event_pattern=events.EventPattern(),
event_bus=events.from_event_bus_arn(), # imported
targets=#APIDestination with params and transformer, dont know method ???
)
这个可以实现吗?
或者谁知道 EventTarget
的哪种方法能够将现有资源导入 cdk?
文档:
https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_events/EventBus.html
L1 CfnRule 构造可以针对现有 API 目标和自定义总线创建新规则。它还可以选择应用输入转换:
events.CfnRule(
self,
"Rule",
event_bus_name="my-bus-name",
event_pattern={"source": ["cdk-test"]},
targets=[
events.CfnRule.TargetProperty(
arn="arn:aws:events:us-east-1:xxxx:api-destination/xxxxxxxx",
id="foo_rule",
role_arn="arn:aws:iam::xxxxx:role/xxxxxxxxx",
input_transformer=events.CfnRule.InputTransformerProperty(
input_paths_map={"detail-type": "$.detail-type"},
input_template=json.dumps(
{
"transformed": '{"name": "DETAIL_TYPE", "value": <detail-type>}'
}
),
),
)
],
)
由于AWS上的资源是在控制台手动创建的。例如 Rule、EventBus、APIDestination(目标)。表示这些资源不提供任何cdk代码。
要点是我想用现有的 EventBus 和 APIDestination 添加更多 Rule(目标)**。然后自定义input_transformer in targets within cdk code.
from aws_cdk import aws_events as events, aws_events_targets as targets
class TheDestinedLambdaStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
new_rule = events.Rule(
self,
"rule",
event_pattern=events.EventPattern(),
event_bus=events.from_event_bus_arn(), # imported
targets=#APIDestination with params and transformer, dont know method ???
)
这个可以实现吗?
或者谁知道 EventTarget
的哪种方法能够将现有资源导入 cdk?
文档: https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_events/EventBus.html
L1 CfnRule 构造可以针对现有 API 目标和自定义总线创建新规则。它还可以选择应用输入转换:
events.CfnRule(
self,
"Rule",
event_bus_name="my-bus-name",
event_pattern={"source": ["cdk-test"]},
targets=[
events.CfnRule.TargetProperty(
arn="arn:aws:events:us-east-1:xxxx:api-destination/xxxxxxxx",
id="foo_rule",
role_arn="arn:aws:iam::xxxxx:role/xxxxxxxxx",
input_transformer=events.CfnRule.InputTransformerProperty(
input_paths_map={"detail-type": "$.detail-type"},
input_template=json.dumps(
{
"transformed": '{"name": "DETAIL_TYPE", "value": <detail-type>}'
}
),
),
)
],
)