Is it possible to use the current <EventBus> const...
# sst
c
Is it possible to use the current EventBus construct with a Kinesis Stream set as the target? If not, @Frank is this something that could be added? I’m trying to reproduce this Serverless Framework template - https://github.com/jgilbert01/aws-lambda-stream/blob/master/templates/event-hub/serverless.yml The goal is to create a service that consumes all events from other services via EventBridge and and utilizes Kinesis to help apply batching and back pressure for publishing of events to functions – https://medium.com/@jgilbert001/combining-the-best-of-aws-eventbridge-and-aws-kinesis-9b363b043ade
t
AWS CDK doesn't support everything EventBridge can do yet
c
My current stab at this via SST is -
t
Oh but it does support kinesis stream let me see if we support it
c
Thanks Dax
When I run that currently I get
Error: Invalid function definition for the "rule01_target_0" Function
t
Are you using typescript?
c
Not yet - on the list of things to get done learning 😂
But probably know enough to deduce info from it
t
Ah ok give me like 20 min and I'll dig into this
c
Dax, where do I send the coffee? Have no idea how you’re always so responsive but incredibly appreciative of it
g
t
Don't send me coffee! I don't drink it!
g
kinda like this but with the kinesis target
c
Thanks @Garret Harp, I appreciate it. I’m still getting hands around right ways to compose SST and CDK together. Could I hit you up with some follow-up questions if you have a minute - 1. Is the ‘targets’ prop in screenshot above being applied as part of SST EventBus construct properties or elsewhere? 2. Are all of these resources I should be importing from
@aws-cdk/aws-events
?
g
its in the rules same place you had tried to define the stream in your code example above, and its from
@aws-cdk/aws-events-targets
oh wait no actually I did import aws-events too and used their add rule one sec
Copy code
new events.Rule(this, 'GiveawayStarted', {
			description: 'A Giveaway has been started',
			eventBus: bus.eventBridgeEventBus,
			ruleName: 'GiveawayStarted',
			eventPattern: {
				source: ['softgiving.dynamodb'],
				detailType: ['INSERT'],
				detail: {
					Keys: {
						pk: [{ prefix: 'Campaign#' }],
						sk: ['ActiveGiveaway#']
					}
				}
			},
			targets: [new targets.SfnStateMachine(runGiveaway, {
				input: events.RuleTargetInput.fromObject({
					giveaway: events.EventField.fromPath('$.detail.Record.giveaway'),
					timers: events.EventField.fromPath('$.detail.Record.timers')
				})
			})]
		})
I remember having issues defining some targets without using aws cdk events. I think sst addRules only supports functions queues and sns or some limited set like that
c
Thanks. So in this
events
is coming from something like
import * as events from '@aws-cdk/aws-events';
?
g
yes
c
is
bus
is the instance created via SSTs EventBus construct or are you doing that via CDK as well?
g
the bus is created from sst still
c
It looks like you don’t need to use the SST KinesisStream construct since that will be created directly via CDK
targets
 –and
targets
is imported from
@aws-cdk/aws-events-targets
, right?
g
Havent used the kinesis streams at all so not sure about that but yes targets is from aws-events-targets
c
Cool. Thanks again
Ok, it looks like you may still need to create stream and then reference it in targets method, similar to
runGiveaway
in your code example; which I’m assuming was a resource defined elsewhere. Inch by inch. Thanks for all the help gents
t
were you able to get this?
c
Thanks for checking Dax - I think I may gotten this sorted. It is building at
start
now. I need to test some events through it to see if it’s connected like I think it is. Here’s where I landed within the SST stack definition -
f
Hey @Clayton, I opened an issue to add KinesisStream support for EventBus https://github.com/serverless-stack/serverless-stack/issues/991
Once that’s supported, the code above should look more compact.
c
Fantastic, thank you @Frank
Fwiw – here’s where I ended up after converting it to use TypeScript. I had to replace the SST EventBus and KinesisStream constructs with their CDK equivalents since the CDK Rule construct expected these and was throwing TS errors –
f
@Clayton You can get the CDK stream/bus from the SST constructs, for example
Copy code
const bus = sst.EventBus(...);
const stream = sst.KinesisStream(...);

// bus.eventBridgeEventBus is events.EventBus
// stream.kinesisStream is kinesis.Stream
c
Thanks @Frank I had done that originally, but when I converted it to TS the CDK Rule threw errors when I tried to pass it in the SST created EventBus and Stream (not recognizing them as an expected types). Is there way to work around that to still use the SST constructs?
f
Just to clarify, did you pass in
bus
or
bus.eventBridgeEventBus
to the CDK Rule?
c
Ah, I misunderstood. That does work, thanks @Frank . In terms of learning - beyond the terser code are there other benefits to using the SST constructs in a case like this (e.g. quicker builds w/o extra CDK imports)?
f
Not much benefit. Might be easier to move it over once
sst.EventBus
supports
sst.Stream
target 😁