【发布时间】:2021-10-03 10:58:23
【问题描述】:
我正在尝试设置规则以使用 CDK 将事件从一个事件总线发送到同一帐户中的另一个。
我遇到的问题是 Rule() 只接受实现 IRuleTarget 的东西。
创建新的事件总线会返回实现 IRuleTarget 的 EventBus 类。 但是查找 EventBus 会返回没有实现 IRuleTarget 的 IEventBus。
有没有办法可以查找我的事件总线并将其作为目标应用到规则?
// Define EventBus1
const eventBus1 = new EventBus(this, 'eventBus1', {
eventBusName: 'eventBus1Name',
});
// Look up my Event Bus in the other account, this method returns an IEventBus
const iEventBus2 = EventBus.fromEventBusArn(this, 'eventBus2', 'eventBus2Arn');
// My bad attempt to convert it, this didn't seem to work
const eventBus2 = EventBus.bind(iEventBus2);
// Create Rule to send event from eventBus1 to eventBus2
const eventBus1ToEventBus2Rule = new Rule(this, 'eventBus1ToEventBus2Rule', {
eventBus: eventBus1,
eventPattern: {
'detailType': ['eventDetailType'],
},
});
// Fails with in error I'll copy in below
eventBus1ToEventBus2Rule.addTarget(eventBus2);
错误:解决错误:提供的属性不正确 “CfnRuleProps”目标:元素 0:提供的属性不正确 对于“目标属性” arn:必需但缺少。
这是使用 1.115.0 版本的 aws-cdk。 一切都是通过 EventBridge 构建的。
【问题讨论】:
标签: typescript amazon-web-services aws-cdk aws-event-bridge