Skip to content

Commit 1151a3a

Browse files
authored
feat: add support for Step Functions (CodeGenieApp#668)
1 parent 6eaeb0a commit 1151a3a

File tree

6 files changed

+39
-3
lines changed

6 files changed

+39
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ serverlessExpress({
281281
'AWS_SQS': '/sqs'
282282
'AWS_EVENTBRIDGE': '/eventbridge',
283283
'AWS_KINESIS_DATA_STREAM': '/kinesis',
284+
'AWS_S3': '/s3',
285+
'AWS_STEP_FUNCTIONS': '/step-functions',
284286
}
285287
})
286288
```

src/configure.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Handler } from 'aws-lambda';
33
import { Logger } from './logger';
44
import Framework from './frameworks';
55

6-
type EventSources = 'AWS_SNS' | 'AWS_DYNAMODB' | 'AWS_EVENTBRIDGE' | 'AWS_SQS' | 'AWS_KINESIS_DATA_STREAM' | 'AWS_S3';
6+
type EventSources = 'AWS_SNS' | 'AWS_DYNAMODB' | 'AWS_EVENTBRIDGE' | 'AWS_SQS' | 'AWS_KINESIS_DATA_STREAM' | 'AWS_S3' | 'AWS_STEP_FUNCTIONS';
77

88
interface EventSource {
99
getRequest?: any; // TODO:
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const getRequestValuesFromStepFunctions = ({ event }) => {
2+
const method = 'POST'
3+
const headers = { host: 'stepfunctions.amazonaws.com' }
4+
const body = event
5+
6+
return {
7+
method,
8+
headers,
9+
body
10+
}
11+
}
12+
13+
const getResponseToStepFunctions = ({
14+
body,
15+
isBase64Encoded = false
16+
}) => {
17+
if (isBase64Encoded) {
18+
throw new Error('base64 encoding is not supported')
19+
}
20+
21+
return JSON.parse(body)
22+
}
23+
24+
module.exports = {
25+
getRequest: getRequestValuesFromStepFunctions,
26+
getResponse: getResponseToStepFunctions
27+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { getRequest, getResponse } = require('./http-function-runtime-v3')
22

33
module.exports = {
4-
getRequest: getRequest,
5-
getResponse: getResponse
4+
getRequest,
5+
getResponse
66
}

src/event-sources/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const azureHttpFunctionV4EventSource = require('./azure/http-function-runtime-v4
1010
const awsEventBridgeEventSource = require('./aws/eventbridge')
1111
const awsKinesisEventSource = require('./aws/kinesis')
1212
const awsS3 = require('./aws/s3')
13+
const awsStepFunctionsEventSource = require('./aws/step-functions')
1314

1415
function getEventSource ({ eventSourceName }) {
1516
switch (eventSourceName) {
@@ -37,6 +38,8 @@ function getEventSource ({ eventSourceName }) {
3738
return awsKinesisEventSource
3839
case 'AWS_S3':
3940
return awsS3
41+
case 'AWS_STEP_FUNCTIONS':
42+
return awsStepFunctionsEventSource
4043
default:
4144
throw new Error('Couldn\'t detect valid event source.')
4245
}

src/event-sources/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ function getEventSourceNameBasedOnEvent ({
127127
return 'AWS_EVENTBRIDGE'
128128
}
129129

130+
if (event.context && event.context.Execution && event.context.State && event.context.StateMachine) {
131+
return 'AWS_STEP_FUNCTIONS'
132+
}
133+
130134
throw new Error('Unable to determine event source based on event.')
131135
}
132136

0 commit comments

Comments
 (0)