Hello,
I want to create the following resources:
- EventBridge Bus
- SNS Topic
- Lambda Function
I want to see a event pattern matching rule to the Bus, and add the SNS Topic as the target.
And I want to add the Lambda Function as the subscriber to the SNS Topic.
So the workflow is basically as follows:
EventBridge Bus => SNS Topic => Lambda
I’m trying to use EventBus
and Topic
constructs from @serverless-stack/resources
, but it seems like the EventBus
construct allows only Queue
and Functilon
constructs to be added as targets
.
This is what my stack looks like right now, and I couldn’t manage to achieve what I want:
import { App, Stack, StackProps, Topic, EventBus } from "@serverless-stack/resources";
export class MainStack extends Stack {
constructor(scope: App, id: string, props?: StackProps) {
super(scope, id, props);
// The SNS Topic that EventBridge Bus targets
const snsTopic = new Topic(this, "Topic", {
subscribers: ["src/sns/fallback/index.main"],
snsTopic: {
topicName: 'FallbackTopic',
displayName: 'Fallback'
}
});
// The EventBus that targets the SNS Topic
const eventBus = new EventBus(this, id, {
eventBridgeEventBus: {
eventBusName: 'FallbackBus'
},
rules: {
fallbackEventRule: {
description: 'The rule to match with events that comes from fallback handler',
ruleName: 'fallbackEventRule',
eventPattern: {
account: [scope.account],
},
}
}
})
this.addOutputs({
EventBusName: eventBus.eventBusName,
SNSTopicName: snsTopic.topicName
});
}
}
How can I add the SNS Topic as the target?