Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support step-functions #668

Merged
merged 5 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ serverlessExpress({
'AWS_SQS': '/sqs'
'AWS_EVENTBRIDGE': '/eventbridge',
'AWS_KINESIS_DATA_STREAM': '/kinesis',
'AWS_S3': '/s3',
'AWS_STEP_FUNCTIONS': '/step-functions',
}
})
```
Expand Down
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' | 'AWS_S3';
type EventSources = 'AWS_SNS' | 'AWS_DYNAMODB' | 'AWS_EVENTBRIDGE' | 'AWS_SQS' | 'AWS_KINESIS_DATA_STREAM' | 'AWS_S3' | 'AWS_STEP_FUNCTIONS';

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

return {
method,
headers,
body
}
}

const getResponseToStepFunctions = ({
body,
isBase64Encoded = false
}) => {
if (isBase64Encoded) {
throw new Error('base64 encoding is not supported')
}

return JSON.parse(body)
}

module.exports = {
getRequest: getRequestValuesFromStepFunctions,
getResponse: getResponseToStepFunctions
}
4 changes: 2 additions & 2 deletions src/event-sources/azure/http-function-runtime-v4.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { getRequest, getResponse } = require('./http-function-runtime-v3')

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

function getEventSource ({ eventSourceName }) {
switch (eventSourceName) {
Expand Down Expand Up @@ -37,6 +38,8 @@ function getEventSource ({ eventSourceName }) {
return awsKinesisEventSource
case 'AWS_S3':
return awsS3
case 'AWS_STEP_FUNCTIONS':
return awsStepFunctionsEventSource
default:
throw new Error('Couldn\'t detect valid event source.')
}
Expand Down
4 changes: 4 additions & 0 deletions src/event-sources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ function getEventSourceNameBasedOnEvent ({
return 'AWS_EVENTBRIDGE'
}

if (event.context && event.context.Execution && event.context.State && event.context.StateMachine) {
return 'AWS_STEP_FUNCTIONS'
}

throw new Error('Unable to determine event source based on event.')
}

Expand Down