-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[aws-events-targets] add a target for a cross-account eventbus #9473
[aws-events-targets] add a target for a cross-account eventbus #9473
Comments
Yep, this would probably be a good idea. Thanks for the request. It's unlikely we will take this on quickly but you should be able to add it yourself in a PR if you want. |
I would like to have a go at this, if that's ok? I have a similar requirement. |
Please add this feature! It's important! |
I have implemented this as follows. It works well for me... import { RuleTargetConfig } from "@aws-cdk/aws-events";
import { IRule } from "@aws-cdk/aws-events/lib/rule-ref";
import { Effect, PolicyStatement, Role, ServicePrincipal } from "@aws-cdk/aws-iam";
import { ServicePrincipals } from "cdk-constants";
const targetAccountId = "123456789009";
const targetAccountDefaultBus = `arn:aws:events:eu-west-1:${targetAccountId}:event-bus/default`;
const publishingRole = new Role(this, "PublishingRole", {
assumedBy: new ServicePrincipal(ServicePrincipals.EVENTS)
});
publishingRole.addToPolicy(
new PolicyStatement({
effect: Effect.ALLOW,
resources: [targetAccountDefaultBus],
actions: [
"events:PutEvents"
]
})
);
// This rule captures authentication events and sends it to the
// default EventBridge bus in the other account
const rule = new Rule(this, "EventRule", {
description: "Captures events",
ruleName: "EventRule",
enabled: true,
eventPattern: {
source: ["aws.someservice"]
}
});
rule.addTarget({
bind(_rule: IRule, generatedTargetId: string): RuleTargetConfig {
return {
arn: targetAccountDefaultBus,
id: generatedTargetId,
role: publishingRole
};
}
}); Don't forget to also log into the target account and set the default bus to permit submissions from the origin account (or Organisation as a whole). Have a go, see if it works out for you. Be good to get a formal version though too... |
Sorry I'm having a lot of trouble getting the project to build 🙁 |
thanks @hlascelles for the inspiration. dirty python code that works for me: @jsii.implements(events.IRuleTarget)
class EventBridgeEventTarget:
def __init__(
self,
id: str,
target_account_id: str,
role: iam.Role,
target_region: str = "eu-west-1",
target_topic: str = "default",
) -> None:
self.id = id
self.role = role
self.target_account_id = target_account_id
self.target_region = target_region
self.target_topic = target_topic
def bind(self, rule, id=None):
return events.RuleTargetConfig(
arn=f"arn:aws:events:{self.target_region}:{self.target_account_id}:event-bus/{self.target_topic}",
role=self.role,
id=self.id,
) |
@alanraison see if this helps, its basically the same thing that @hlascelles posted but a bit more stand-alone (they're referencing a few things that are specific to they're code base)
|
I used the below to send event to a different account's default bus. I was setting up the event on step function status change to SUCCEEDED
You just have to create a targetProperty and give the arn of target event bus. |
Closes #9473 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
I would like a "CrossAccountEventBus" target in aws_events_targets that allows me to forward events to the default eventbus of a different account.
I did see https://docs.aws.amazon.com/cdk/api/latest/docs/aws-events-readme.html#cross-account-targets - but this seems to make changes in the target account which doesn't work in my case.
Use Case
I have a target account where the default eventbus has already been configured with a policy accept forwarded events, I would like to create a rule that targets this cross-account eventbus.
Proposed Solution
A target in aws_events_targets (like https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events-targets.SnsTopic.html) but that only has an ARN property.
Other
I'm opening this feature request as was recommended to another commenter here: #2850
I'm currently working around this by using the CfnRule, but this is a bit of a bummer as I can use the very handy
.on_xxx
methods.This is a 🚀 Feature Request
The text was updated successfully, but these errors were encountered: