-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
380a19d
commit de7a4de
Showing
15 changed files
with
150 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
carpark/functions/carpark-event.js → carpark/functions/carpark-bucket-event.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import { EventBridge } from '@aws-sdk/client-eventbridge' | ||
|
||
import { notifyBusNewCar } from '../event-bridge/index.js' | ||
import { notifyBus } from '../event-bridge/source.js' | ||
|
||
const CARPARK_BUS_ARN = process.env.CARPARK_BUS_ARN || '' | ||
const EVENT_BUS_ARN = process.env.EVENT_BUS_ARN || '' | ||
|
||
/** | ||
* @param {import('aws-lambda').S3Event} event | ||
*/ | ||
async function handler(event) { | ||
const bus = new EventBridge({}) | ||
|
||
return await notifyBusNewCar(event, bus, CARPARK_BUS_ARN) | ||
return await notifyBus(event, bus, EVENT_BUS_ARN) | ||
} | ||
|
||
export const carparkBucketConsumer = handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export const SATNAV_EVENT_BRIDGE_SOURCE_EVENT = 'carpark_bucket' | ||
|
||
/** | ||
* @typedef {{ detail: {key?: string, region: string, bucketName: string}}} EventBridgeEvent | ||
*/ | ||
|
||
/** | ||
* @param {import('aws-lambda').S3Event} event | ||
* @param {import('@aws-sdk/client-eventbridge').EventBridge} eventBridge | ||
* @param {string} eventBusName | ||
*/ | ||
export async function notifyBus(event, eventBridge, eventBusName) { | ||
const entries = event.Records | ||
? event.Records.map((r) => ({ | ||
key: r?.s3?.object?.key, | ||
region: r?.awsRegion || 'us-west-2', | ||
bucketName: r?.s3?.bucket?.name, | ||
})).filter((entry) => entry.key) | ||
: [] | ||
|
||
if (entries.length > 0) { | ||
const feedbackEntries = entries.map((entry) => ({ | ||
EventBusName: eventBusName, | ||
Source: SATNAV_EVENT_BRIDGE_SOURCE_EVENT, | ||
DetailType: 'satnav_index_added', | ||
Detail: JSON.stringify(entry), | ||
})) | ||
await eventBridge.putEvents({ Entries: feedbackEntries }) | ||
} | ||
|
||
return { | ||
statusCode: 200, | ||
headers: { 'Content-Type': 'text/plain' }, | ||
body: `File was added to satnav bucket`, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.