Skip to content

Instantly share code, notes, and snippets.

@kylenstone
Created September 19, 2020 01:12
Show Gist options
  • Save kylenstone/25f432f29eb3a75a25ece5afb88deed2 to your computer and use it in GitHub Desktop.
Save kylenstone/25f432f29eb3a75a25ece5afb88deed2 to your computer and use it in GitHub Desktop.
Frame.io Custom Action Backup to S3 Code: Lambda #1
const { fetchAsset, invokeLambda } = require('./modules/api');
exports.handler = async function (event, context) {
// Save the X-ray Trace ID and and this Lambda's function name.
// We'll pass them to our second 'file handler' Lambda.
const firstLambdaTraceID = process.env._X_AMZN_TRACE_ID;
const caller = context.functionName;
let id = JSON.parse(event.body).resource.id;
let { url, name} = await fetchAsset(id);
try {
await invokeLambda(caller, firstLambdaTraceID, url, name);
let returnPayload = {
statusCode: 202,
body: JSON.stringify({
'title': 'Job received',
'description': `Your backup job for '${name}' has been triggered.`,
'traceID': `${firstLambdaTraceID}`
})
};
return returnPayload;
} catch(err) {
return (`Hit a problem: ${err.message}`);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment