Skip to content

Commit

Permalink
added AWS S3 Event Source (#632)
Browse files Browse the repository at this point in the history
* added AWS S3 Event Source

* Update s3.js

---------

Co-authored-by: Jon Greenwood <[email protected]>
Co-authored-by: Brett Andrews <[email protected]>
  • Loading branch information
3 people authored Dec 14, 2023
1 parent 1d4d58e commit 1132c1a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/configure.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Handler } from 'aws-lambda';
import { Logger } from './logger';
import Framework from './frameworks';

type EventSources = 'AWS_SNS' | 'AWS_DYNAMODB' | 'AWS_EVENTBRIDGE' | 'AWS_SQS' | 'AWS_KINESIS_DATA_STREAM';
type EventSources = 'AWS_SNS' | 'AWS_DYNAMODB' | 'AWS_EVENTBRIDGE' | 'AWS_SQS' | 'AWS_KINESIS_DATA_STREAM' | 'AWS_S3';

interface EventSource {
getRequest?: any; // TODO:
Expand Down
28 changes: 28 additions & 0 deletions src/event-sources/aws/s3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const getRequestValuesFromS3 = ({ event }) => {
const method = 'POST'
const headers = { host: 's3.amazonaws.com' }
const body = event

return {
method,
headers,
body
}
}

const getResponseToS3 = ({
statusCode,
body,
headers,
isBase64Encoded
}) => ({
statusCode,
headers,
body,
isBase64Encoded
})

module.exports = {
getRequest: getRequestValuesFromS3,
getResponse: getResponseToS3
}
3 changes: 3 additions & 0 deletions src/event-sources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const azureHttpFunctionV3EventSource = require('./azure/http-function-runtime-v3
const azureHttpFunctionV4EventSource = require('./azure/http-function-runtime-v4')
const awsEventBridgeEventSource = require('./aws/eventbridge')
const awsKinesisEventSource = require('./aws/kinesis')
const awsS3 = require('./aws/s3')

function getEventSource ({ eventSourceName }) {
switch (eventSourceName) {
Expand All @@ -34,6 +35,8 @@ function getEventSource ({ eventSourceName }) {
return awsEventBridgeEventSource
case 'AWS_KINESIS_DATA_STREAM':
return awsKinesisEventSource
case 'AWS_S3':
return awsS3
default:
throw new Error('Couldn\'t detect valid event source.')
}
Expand Down

0 comments on commit 1132c1a

Please sign in to comment.