Created
July 3, 2017 17:09
-
-
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.
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
/** | |
* 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' | |
} | |
}); | |
}; |
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
/** | |
* Return a HTTP redirect. | |
*/ | |
module.exports.handler = function(event, context, callback) { | |
callback(null, { | |
statusCode: 301, | |
body: '', | |
headers: { | |
'Location': 'https://www.google.com' | |
} | |
}); | |
}; |
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
/** | |
* Return a JSON string. | |
*/ | |
module.exports.handler = function(event, context, callback) { | |
callback(null, { | |
statusCode: 200, | |
body: JSON.stringify({ | |
foo: 'bar' | |
}) | |
}); | |
}; |
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
/** | |
* 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