Last active
February 5, 2020 03:13
-
-
Save serg06/177a96cfe0a2432435de6132d62d5da5 to your computer and use it in GitHub Desktop.
Amazon Lambda Node.js 12.x async handler function example
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
/* Grr, Amazon's documentation sucks! | |
* Their own documentation: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html | |
* says that you're allowed to return strings, but that always results in "Internal Server Error"! | |
* In reality, your result has to be structured like the one you see below. | |
*/ | |
exports.handler = async (event, context) => { | |
return { | |
statusCode: 200, | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({"here is": "an example"}) | |
}; | |
} | |
/* Note: | |
* | |
* They say you can return "a response, error, or promise." | |
* | |
* If you want to return a promise, do resolve(the same response format as above). | |
* If you want to return an error, not sure what exactly the response should look like, | |
* I'm guessing it should be the same but with statusCode set to some error status code. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment