简体   繁体   中英

How to integrate new cdk stack with existed aws EventBridge (EventTarget)

Since the resources on AWS have been created by manual on console. eg Rule , EventBus , APIDestination (Target). Means these resource doesn't provide any cdk code.

Point is I want to add more Rule with existing EventBus and APIDestination (Target)**. Then customize 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 ???
        )

It's possible to implement this?
or anyone know which method of EventTarget able to import existed resource to cdk?

Docs: https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_events/EventBus.html

The L1 CfnRule construct can create a new Rule targeting an existing API Destination and custom bus. It can also optionally apply input transforms:

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>}'
                    }
                ),
            ),
        )
    ],
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM