Skip to content

Instantly share code, notes, and snippets.

@codecitizen
Last active August 13, 2019 10:35
Show Gist options
  • Save codecitizen/715cff0d5bf0c4ad54046afaea0159ae to your computer and use it in GitHub Desktop.
Save codecitizen/715cff0d5bf0c4ad54046afaea0159ae to your computer and use it in GitHub Desktop.
// POST /trigger { path: "" }
module.exports.trigger = async (event, context) => {
const id = uuid();
await stepfunctions.startExecution({
stateMachineArn: process.env.STATE_MACHINE_ARN,
input: JSON.stringify(event.body),
name: id
});
return {
statusCode: 202,
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
id: id
})
};
};
// GET /status?id=...
module.exports.status = async (event, context) => {
// The Execution ID is given as query string parameter "id"
const id = event.queryStringParameters.id;
// The ARN including region, AWS account ID to the step functions execution
// is stored in the "EXECUTION_ARN" environment variable. We just need to
// add the execution ID to the end.
const executionState = await stepfunctions.describeExecution({
executionArn: process.env.EXECUTION_ARN + id
}).promise();
return {
statusCode: 200,
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
state: executionState.status,
data: executionState.output
})
};
};
functions:
trigger:
handler: handler.trigger
events:
- http: POST /trigger
environment:
STATE_MACHINE_ARN: "arn:aws:states:#{AWS::Region}:#{AWS::AccountId}:stateMachine:PDFTransform"
status:
handler: handler.status
events:
- http: GET /trigger
environment:
EXECUTION_ARN: "arn:aws:states:#{AWS::Region}:#{AWS::AccountId}:execution:PDFTransform:"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment