Skip to content

Commit

Permalink
feat: add support for eventbridge customer events (#676)
Browse files Browse the repository at this point in the history
  • Loading branch information
martoncsikos authored Mar 12, 2024
1 parent 1376bd0 commit 9e1a52b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
12 changes: 10 additions & 2 deletions __tests__/unit.eventbridge.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const eventSources = require('../src/event-sources')
const testUtils = require('./utils')

const dynamodbEventSource = eventSources.getEventSource({
const eventbridgeEventSource = eventSources.getEventSource({
eventSourceName: 'AWS_EVENTBRIDGE'
})

Expand All @@ -21,7 +21,15 @@ test('request is correct (scheduled)', () => {
expect(req.method).toEqual('POST')
})

test('request is correct (customer event)', () => {
const req = getReq({ event: testUtils.eventbridgeCustomerEvent })
expect(typeof req).toEqual('object')
expect(req.headers).toEqual({ host: 'events.amazonaws.com' })
expect(req.body).toEqual(testUtils.eventbridgeCustomerEvent)
expect(req.method).toEqual('POST')
})

function getReq ({ event }) {
const request = dynamodbEventSource.getRequest({ event })
const request = eventbridgeEventSource.getRequest({ event })
return request
}
21 changes: 21 additions & 0 deletions __tests__/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,21 @@ const eventbridgeScheduledEvent = {
resources: ['arn:aws:events:us-east-2:123456789012:rule/my-schedule']
}

const eventbridgeCustomerEvent = {
version: '0',
id: 'fe8d3c65-xmpl-c5c3-2c87-81584709a377',
source: 'com.mycompany.myapp',
account: '123456789012',
time: '2016-01-14T01:02:03Z',
region: 'us-east-2',
resources: [
'resource1',
'resource2'
],
'detail-type': 'myDetailType',
detail: {}
}

// Sample event from https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis-example.html
const kinesisDataStreamEvent = {
Records: [
Expand Down Expand Up @@ -257,6 +272,11 @@ describe('getEventSourceNameBasedOnEvent', () => {
const result = getEventSourceNameBasedOnEvent({ event: eventbridgeScheduledEvent })
expect(result).toEqual('AWS_EVENTBRIDGE')
})

test('recognizes eventbridge customer event', () => {
const result = getEventSourceNameBasedOnEvent({ event: eventbridgeCustomerEvent })
expect(result).toEqual('AWS_EVENTBRIDGE')
})
})

module.exports = {
Expand All @@ -266,5 +286,6 @@ module.exports = {
sqsEvent,
eventbridgeEvent,
eventbridgeScheduledEvent,
eventbridgeCustomerEvent,
kinesisDataStreamEvent
}
1 change: 0 additions & 1 deletion src/event-sources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ function getEventSourceNameBasedOnEvent ({
event.id &&
event['detail-type'] &&
event.source &&
event.source.startsWith('aws.') && // Might need to adjust this for "Partner Sources", e.g. Auth0, Datadog, etc
event.account &&
event.time &&
event.region &&
Expand Down

0 comments on commit 9e1a52b

Please sign in to comment.