Ömer Toraman
11/13/2021, 10:06 PMimport * as sst from "@serverless-stack/resources"
import * as events from '@aws-cdk/aws-events'
new sst.EventBus(this, 'myBus', {
eventBridgeEventBus: {
eventBusArn: events.EventBus.fromEventBusArn(this, 'ImportedBus', 'eventBusArn'
}
})
Seems the same with an example in the docs:
https://docs.serverless-stack.com/constructs/EventBus#importing-an-existing-eventbusthdxr
11/13/2021, 10:07 PMthdxr
11/13/2021, 10:07 PMÖmer Toraman
11/13/2021, 10:07 PMType 'IEventBus' is not assignable to type 'string'.ts(2322)
Ömer Toraman
11/13/2021, 10:08 PMType '{ eventBusArn: string; }' is not assignable to type 'IEventBus | EventBusProps | undefined'.
lolÖmer Toraman
11/13/2021, 10:13 PMconst ev = events.EventBus.fromEventBusArn(this, 'ImportedBus', 'order')
new sst.EventBus(this, 'myBus', {
eventBridgeEventBus: ev
})
thdxr
11/13/2021, 10:14 PMÖmer Toraman
11/13/2021, 10:15 PMÖmer Toraman
11/13/2021, 10:15 PMÖmer Toraman
11/13/2021, 10:16 PMputEvents
to the route handler
const api = new sst.Api(this, "Api", {
routes: {
"POST /": "src/lambda.handler",
},
});
const ev = events.EventBus.fromEventBusName(this, 'ImportedBus', 'order')
new sst.EventBus(this, 'myBus', {
eventBridgeEventBus: ev
})
thdxr
11/13/2021, 10:17 PM"POST /": {
permissions: [bus],
handler: "src/lambda.handler"
}
Ömer Toraman
11/13/2021, 10:17 PMthdxr
11/13/2021, 10:18 PMdefaultFunctionProps
in the apiÖmer Toraman
11/13/2021, 10:19 PMputEvents
?Ömer Toraman
11/13/2021, 10:20 PMÖmer Toraman
11/13/2021, 10:21 PM[ [bus, "putEvents"] ]
thdxr
11/13/2021, 10:21 PMgrantPutEvents
but yeahÖmer Toraman
11/13/2021, 10:22 PMthdxr
11/13/2021, 10:27 PMgrant
methods it hasthdxr
11/13/2021, 10:27 PMthdxr
11/13/2021, 10:27 PMÖmer Toraman
11/13/2021, 10:28 PMÖmer Toraman
11/13/2021, 10:28 PMÖmer Toraman
11/13/2021, 10:29 PMgrants
?Ömer Toraman
11/13/2021, 10:29 PMputEvents
, PutItem
etcÖmer Toraman
11/13/2021, 10:30 PMÖmer Toraman
11/13/2021, 10:30 PM*grantPutEventsTo*
Ömer Toraman
11/13/2021, 10:31 PMÖmer Toraman
11/13/2021, 10:51 PMÖmer Toraman
11/13/2021, 11:08 PMsst.EventBus
at all. I could not attach permission using it.
This is what I did:
import * as sst from "@serverless-stack/resources"
import * as events from '@aws-cdk/aws-events'
export class MainStack extends sst.Stack {
constructor(scope: <http://sst.App|sst.App>, id: string, props?: sst.StackProps) {
super(scope, id, props);
const ev = events.EventBus.fromEventBusName(this, 'ImportedBus', 'orders')
const bus = new sst.EventBus(this, 'myBus', {
eventBridgeEventBus: ev
})
// Create a HTTP API
const api = new sst.Api(this, "Api", {
routes: {
"POST /": {
permissions: [[bus, 'grantPutEventsTo']],
handler: "src/lambda.handler",
}
},
});
// Show the endpoint in the output
this.addOutputs({
"ApiEndpoint": api.url,
});
}
}
And I kept getting the error above, and it makes sense honestly, since sst.EventBus
does not have grantPutEventsTo
instance method.Ömer Toraman
11/13/2021, 11:09 PMimport * as sst from "@serverless-stack/resources"
import * as events from '@aws-cdk/aws-events'
export class MainStack extends sst.Stack {
constructor(scope: <http://sst.App|sst.App>, id: string, props?: sst.StackProps) {
super(scope, id, props);
const ev = events.EventBus.fromEventBusName(this, 'ImportedBus', 'orders')
// Create a HTTP API
const api = new sst.Api(this, "Api", {
routes: {
"POST /": {
// @ts-expect-error
permissions: [[ev, 'grantPutEventsTo']],
handler: "src/lambda.handler",
}
},
});
// Show the endpoint in the output
this.addOutputs({
"ApiEndpoint": api.url,
});
}
}
And it worked, now I see that the Lambda has a permission to putEvents, however, I had to suprass typescript error, as it did not accept ev
Derek Kershner
11/15/2021, 9:40 PMÖmer Toraman
11/15/2021, 10:30 PMDerek Kershner
11/15/2021, 10:30 PMÖmer Toraman
11/15/2021, 10:32 PMÖmer Toraman
11/15/2021, 10:32 PMÖmer Toraman
11/15/2021, 10:33 PMDerek Kershner
11/15/2021, 10:37 PM// @ts-expect-error
Ömer Toraman
11/15/2021, 10:47 PM