Skip to content

Instantly share code, notes, and snippets.

@rlingineni
Created November 4, 2018 06:58
Show Gist options
  • Save rlingineni/1021c916e49d36ab415b648bcac5bfcc to your computer and use it in GitHub Desktop.
Save rlingineni/1021c916e49d36ab415b648bcac5bfcc to your computer and use it in GitHub Desktop.
AWS Lambda Proxy Response Builder
// Helper function for AWS Lambda API responses, can pass in JSON or string and status code and message to respond with
function BuildResponse(statusCode, responseBody, shouldStringify = false) {
let body = "invalid response";
if (shouldStringify) {
body = JSON.stringify(responseBody);
} else {
body = JSON.stringify({ msg: responseBody });
}
let response = {
statusCode,
body
};
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment