Skip to content

Commit

Permalink
Hello world state machine
Browse files Browse the repository at this point in the history
  • Loading branch information
kdid committed Aug 15, 2023
1 parent 5fa78cd commit 235d9c0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
11 changes: 11 additions & 0 deletions StateMachine.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
1 change: 1 addition & 0 deletions aws-stepfunctions-local-credentials.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LAMBDA_ENDPOINT=http://localhost:3001/
1 change: 1 addition & 0 deletions src/handlers/get-auth-whoami.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 14 additions & 2 deletions src/handlers/get-file-set-download.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const AWS = require("aws-sdk");
const { wrap } = require("./middleware");
const { getFileSet } = require("../api/opensearch");
const opensearchResponse = require("../api/response/opensearch");
Expand All @@ -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")
}
Expand All @@ -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" },
Expand Down

0 comments on commit 235d9c0

Please sign in to comment.