Ömer Toraman
10/17/2021, 2:02 PMsst.EventBus
construct? It seems like it only allows for lambda and SQS targetsÖmer Toraman
10/17/2021, 2:23 PMeventBus
to put events into snsTopic
import { App, Stack, StackProps, EventBus, Topic } from "@serverless-stack/resources";
export class MainStack extends Stack {
constructor(scope: App, id: string, props?: StackProps) {
super(scope, id, props);
const snsTopic = new Topic(this, "Topic", {
subscribers: ["src/sns/fallback/index.main"],
snsTopic: {
topicName: 'FallbackTopic',
displayName: 'Fallback'
},
});
const eventBus = new EventBus(this, id, {
eventBridgeEventBus: {
eventBusName: 'FallbackBus',
},
})
this.addOutputs({
EventBusName: eventBus.eventBusName,
SNSTopicName: snsTopic.topicName
});
}
}
Ömer Toraman
10/17/2021, 3:30 PMnode_modules/@serverless-stack/resources/src/EventBus.ts
) I see that it is not possible to add anything other than Queue or Function as the target, though TypeScript already tells that. 🥲Omi Chowdhury
10/17/2021, 4:06 PMeventBus.eventBridgeEventBus
for nowÖmer Toraman
10/17/2021, 4:30 PMÖmer Toraman
10/17/2021, 4:31 PMimport * as sst from '@serverless-stack/resources'
import * as events from '@aws-cdk/aws-events'
import * as targets from '@aws-cdk/aws-events-targets'
export class MainStack extends sst.Stack {
constructor(scope: <http://sst.App|sst.App>, id: string, props?: sst.StackProps) {
super(scope, id, props)
const eventBus = new events.EventBus(this, id, {
eventBusName: 'FallbackBus'
})
const snsTopic = new sst.Topic(this, 'SNSTopic', {
snsTopic: {
topicName: 'FallbackTopic'
}
})
const snsTarget = new targets.SnsTopic(snsTopic.snsTopic)
const fallbackRule = new events.Rule(this, 'FallbackRule', {
description: 'Put events to SNS Topic',
eventBus,
ruleName: 'FallbackRule',
targets: [snsTarget],
eventPattern: {
account: [scope.account],
}
})
const api = new sst.ApiGatewayV1Api(this, 'Api', {
routes: {
'POST /create-event': 'src/handlers/apiGateway/create-event/index.main'
}
})
this.addOutputs({
EventBusName: eventBus.eventBusName,
SNSTopicName: snsTopic.topicName,
RESTEndpoint: api.url
})
}
}
Not sure if I got it right, but will seeOmi Chowdhury
10/17/2021, 4:34 PMÖmer Toraman
10/17/2021, 6:01 PMÖmer Toraman
10/17/2021, 6:01 PM.env
,
stacks/index.js
or basically the stack in which I’m defining the EventBusÖmer Toraman
10/17/2021, 6:02 PMimport * as sst from '@serverless-stack/resources'
import * as events from '@aws-cdk/aws-events'
import * as targets from '@aws-cdk/aws-events-targets'
const handlerDir = 'src/handlers/'
export class MainStack extends sst.Stack {
constructor(scope: <http://sst.App|sst.App>, id: string, props?: sst.StackProps) {
super(scope, id, props)
const eventBus = new events.EventBus(this, id, {
eventBusName: 'FallbackBus'
})
const snsTopic = new sst.Topic(this, 'SNSTopic', {
snsTopic: {
topicName: 'FallbackTopic',
}
})
const snsTarget = new targets.SnsTopic(snsTopic.snsTopic)
new events.Rule(this, 'FallbackRule', {
description: 'Put events to SNS Topic',
eventBus,
ruleName: 'FallbackRule',
targets: [snsTarget],
eventPattern: {
account: [scope.account],
}
})
const api = new sst.ApiGatewayV1Api(this, 'Api', {
defaultFunctionProps: {
environment: {
eventBusName: eventBus.eventBusName
}
},
routes: {
'POST /create-event': handlerDir + 'apiGateway/create-event/index.main'
}
})
this.addOutputs({
EventBusName: eventBus.eventBusName,
EventBusArn: eventBus.eventBusArn,
SNSTopicName: snsTopic.topicName,
SNSTopicArn: snsTopic.topicArn,
RESTEndpoint: api.url
})
}
}
Omi Chowdhury
10/17/2021, 6:08 PMÖmer Toraman
10/17/2021, 6:17 PMÖmer Toraman
10/17/2021, 6:17 PMenvironment.d.ts
Ömer Toraman
10/17/2021, 6:18 PMdeclare namespace NodeJS {
interface ProcessEnv {
eventBusName: string
}
}
This helpsÖmer Toraman
10/17/2021, 6:18 PMdeclare global {
namespace NodeJS {
interface ProcessEnv {
eventBusName: string
}
}
}
Omi Chowdhury
10/17/2021, 6:19 PMÖmer Toraman
10/17/2021, 6:20 PM