From 235d9c07ea758487059a5059bc6ab1551a4cfe92 Mon Sep 17 00:00:00 2001 From: Karen Shaw Date: Tue, 15 Aug 2023 18:02:37 +0000 Subject: [PATCH] Hello world state machine --- StateMachine.json | 11 +++++++++++ aws-stepfunctions-local-credentials.txt | 1 + src/handlers/get-auth-whoami.js | 1 + src/handlers/get-file-set-download.js | 16 ++++++++++++++-- 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 StateMachine.json create mode 100644 aws-stepfunctions-local-credentials.txt diff --git a/StateMachine.json b/StateMachine.json new file mode 100644 index 00000000..d429b441 --- /dev/null +++ b/StateMachine.json @@ -0,0 +1,11 @@ +{ + "Comment": "Test local step function that calls whomai", + "StartAt": "HelloSF", + "States": { + "HelloSF": { + "Type": "Task", + "Resource": "arn:aws:lambda:us-east-1:123456789012:function:getAuthWhoAmIFunction", + "End": true + } + } +} \ No newline at end of file diff --git a/aws-stepfunctions-local-credentials.txt b/aws-stepfunctions-local-credentials.txt new file mode 100644 index 00000000..7e1ab972 --- /dev/null +++ b/aws-stepfunctions-local-credentials.txt @@ -0,0 +1 @@ +LAMBDA_ENDPOINT=http://localhost:3001/ diff --git a/src/handlers/get-auth-whoami.js b/src/handlers/get-auth-whoami.js index 749bc72d..f8cc99f1 100644 --- a/src/handlers/get-auth-whoami.js +++ b/src/handlers/get-auth-whoami.js @@ -6,6 +6,7 @@ const Honeybadger = require("../honeybadger-setup"); * token if none is present */ exports.handler = wrap(async (event) => { + console.log(event) try { const token = event.userToken; diff --git a/src/handlers/get-file-set-download.js b/src/handlers/get-file-set-download.js index 1511fc0c..b9d4eb20 100644 --- a/src/handlers/get-file-set-download.js +++ b/src/handlers/get-file-set-download.js @@ -1,3 +1,4 @@ +const AWS = require("aws-sdk"); const { wrap } = require("./middleware"); const { getFileSet } = require("../api/opensearch"); const opensearchResponse = require("../api/response/opensearch"); @@ -20,7 +21,7 @@ exports.handler = wrap(async (event) => { if (esResponse.statusCode == "200") { const doc = JSON.parse(esResponse.body) if (downloadAvailable(doc)) { - return processDownload(doc._source.streaming_url, email); + return await processDownload(doc._source.streaming_url, email); } else { return invalidRequest(405, "Download only allowed for role: Access, work_type: Video or Audio, with a valid streaming_url") } @@ -40,7 +41,18 @@ function downloadAvailable(doc) { ); } -function processDownload(streaming_url) { +async function processDownload(streaming_url) { + + var stepfunctions = new AWS.StepFunctions({endpoint: 'http://localhost:8083'}); + + var params = { + stateMachineArn: 'arn:aws:states:us-east-1:123456789012:stateMachine:HelloStepFunction', + name: 'fromAPI', + }; + await stepfunctions.startExecution(params, function(err, data) { + if (err) console.log(err, err.stack); + else console.log(data); + }).promise(); return { statusCode: 200, headers: { "content-type": "text/plain" },