Created
October 4, 2021 01:11
-
-
Save gyrospectre/6c56a851dfa8b67d7acd10c2ce993ee7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const StackTrace = require('error-stack-parser') | |
function check_entrypoint () { | |
var st = StackTrace.parse(new Error()) | |
var entrypoint = st[ st.length -1 ] | |
console.log(serialize(entrypoint)) | |
entry_file = entrypoint.fileName | |
if (!entry_file.startsWith('/var/runtime/')) { | |
var msg = 'Runtime has been tampered with, aborting! File: '+entry_file | |
console.log(msg) | |
throw new Error(msg) | |
} | |
} | |
// Handler | |
exports.handler = async function(event, context) { | |
try { | |
check_entrypoint() | |
responseBody = { 'message': 'Ok!'} | |
let response = { | |
statusCode: 200, | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify(responseBody) | |
} | |
console.log("response: " + serialize(response)) | |
return response | |
} | |
catch(e) { | |
let response = { | |
statusCode: 500, | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify('An error occurred!') | |
} | |
console.log("response: " + serialize(response)) | |
return response | |
} | |
} | |
var serialize = function(object) { | |
return JSON.stringify(object, null, 2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment