generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathinvokeTranslator.js
More file actions
39 lines (35 loc) · 1.16 KB
/
invokeTranslator.js
File metadata and controls
39 lines (35 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const { SFNClient, StartSyncExecutionCommand } = require('@aws-sdk/client-sfn');
const { ApiGatewayManagementApiClient, PostToConnectionCommand } = require('@aws-sdk/client-apigatewaymanagementapi');
const stepfunctions = new SFNClient({});
const apig = new ApiGatewayManagementApiClient({
endpoint: `https://${process.env.APIG_ENDPOINT}`,
});
module.exports.handler = async (event, context) => {
const { body, requestContext: { connectionId, routeKey }} = event;
if (routeKey === "$connect") {
// handle new connection
return {
statusCode: 200
}
}
if (routeKey === "$disconnect") {
// handle disconnection
return {
statusCode: 200
}
}
let params = {
stateMachineArn: process.env.statemachine_arn,
input: body
}
let response = await stepfunctions.send(new StartSyncExecutionCommand(params));
await apig.send(new PostToConnectionCommand({
ConnectionId: connectionId,
Data: response?JSON.stringify( {"url" : JSON.parse(response.output).url} ):"No data"
}));
if ( response && response.output)
response = {"url" : JSON.parse(response.output).url}
return {
statusCode: 200
}
}