Skip to content

Instantly share code, notes, and snippets.

@seeebiii
Created July 3, 2017 17:09
Show Gist options
  • Save seeebiii/406e9b43c665050f1d65793ce7aad18d to your computer and use it in GitHub Desktop.
Save seeebiii/406e9b43c665050f1d65793ce7aad18d to your computer and use it in GitHub Desktop.
A collection of API Gateway responses using AWS Lambda. Send normal success response as well as JSON or HTML or a HTTP redirect.
/**
* Return some HTML code.
*/
module.exports.handler = function(event, context, callback) {
callback(null, {
statusCode: 200,
body: '<html><body><h1>Hello World!</h1></body></html>',
headers: {
'Content-Type': 'text/html'
}
});
};
/**
* Return a HTTP redirect.
*/
module.exports.handler = function(event, context, callback) {
callback(null, {
statusCode: 301,
body: '',
headers: {
'Location': 'https://www.google.com'
}
});
};
/**
* Return a JSON string.
*/
module.exports.handler = function(event, context, callback) {
callback(null, {
statusCode: 200,
body: JSON.stringify({
foo: 'bar'
})
});
};
/**
* Return a usual HTTP 200 response.
*/
module.exports.handler = function(event, context, callback) {
callback(null, {
statusCode: 200,
body: 'Success'
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment