View lambda-integration-serverless.yml
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
functions: | |
hello: | |
handler: handler.hello | |
events: | |
- http: | |
path: users | |
method: get | |
integration: lambda | |
request: | |
template: |
View error-lambda-integration.js
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
module.exports.hello = (event, context, callback) => { | |
const errorResponse = { | |
message: "Error! Dude You sent the wrong parameters" | |
}; | |
// Use JSON.Stringify(), else Integration Response | |
// cannot read your error message. | |
// If not used, the Integration Response will read | |
// the response as [Object Object] which will make it | |
// impossible to detect the status code. |
View success-lambda-integration.js
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
module.exports.hello = (event, context, callback) => { | |
const response = { | |
message: "Success!! You invoked a sleeping Lambda" | |
}; | |
callback(null, response); | |
}; |
View lambda-proxy-serverless.yml
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
functions: | |
hello: | |
handler: handler.hello | |
events: | |
- http: | |
path: hello | |
method: get |
View error-lambda-proxy.js
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
module.exports.hello = (event, context, callback) => { | |
const errorResponse = { | |
statusCode: 400, | |
headers: { | |
"x-custom-header" : "my custom header value" | |
}, | |
body: JSON.stringify({ | |
message: 'Bad request Dude', | |
}), | |
}; |
View success-lambda-proxy.js
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
module.exports.hello = (event, context, callback) => { | |
const response = { | |
statusCode: 200, | |
headers: { | |
"x-custom-header" : "my custom header value" | |
}, | |
body: JSON.stringify({ | |
message: 'Go Serverless v1.0! Your function executed successfully!', | |
input: event, | |
}), |
View Dis-Advantages
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
╔════════════════════════════════════════════════╦═══════════════════════════════════════════════════════╗ | |
║ Lambda-Proxy ║ Lambda ║ | |
╠════════════════════════════════════════════════╬═══════════════════════════════════════════════════════╣ | |
║ 1. Prone to human errors, as status code ║ 1. Involves lot of work in setting up the integration ║ | |
║ and response message will be in code. ║ request template, response template, status code ║ | |
║ This is subjective, but a point to stay in ║ pattern. All these need some extra knowledge on ║ | |
║ the dis-advantage. ║ VTL(Velocity Template Language) and JSON Path. ║ | |
║ ║ ║ | |
║ 2. Everything rests in the code. Headers, ║ ║ | |
║ status codes, messages are hidden in the ║ |
View Advantages
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
╔══════════════════════════════════════════════════════╦═════════════════════════════════════════════════════════════════════════╗ | |
║ Lambda-Proxy ║ Lambda ║ | |
╠══════════════════════════════════════════════════════╬═════════════════════════════════════════════════════════════════════════╣ | |
║ 1. Very Easy to setup. Status code and the response ║ 1. It completely decouples the APIGateway from Lambda's request ║ | |
║ message are in lambda's control. ║ and response payload, its headers and statusCodes. Thus, you ║ | |
║ ║ have more control over the workflow. ║ | |
║ ║ ║ | |
║ 2. Easy for rapid prototyping, as you don't want ║ 2. Provides a procedural way of defining various s |
View Request & Response
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
╔════════════════════════════════════════════════╦════════════════════════════════════════════════╗ | |
║ Lambda-Proxy ║ Lambda ║ | |
╠════════════════════════════════════════════════╬════════════════════════════════════════════════╣ | |
║ - Request from the client are sent directly to ║ - Request and Response can be altered/modified ║ | |
║ lambda. In the same way, responses are ║ when it is sent to and from the lambda. ║ | |
║ sent directly from the lambda. API Gateway ║ API Gateway has full control of the request ║ | |
║ has no part in the transmission data. ║ and responses. ║ | |
║ ║ ║ | |
║ - Status code of the response message such ║ - Status Code of the response message are set ║ | |
║ as 2XX, 4XX & 5XX are set by the lambda. ║ by the API Gateway. ║ |
View General Description
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
╔═════════════════════════════════════════════════════╦════════════════════════════════════════════════════════════╗ | |
║ Lambda-Proxy ║ Lambda ║ | |
╠═════════════════════════════════════════════════════╬════════════════════════════════════════════════════════════╣ | |
║ This is a simple, but powerful integration. All the ║ This is complex, but offers more control over transmission ║ | |
║ request to the APIGateway URL is forwarded ║ data. The request can be modified before it is ║ | |
║ straight to the Lambda and the response is sent ║ sent to lambda and the response can be modified ║ | |
║ from Lambda. i.e No modifications to the ║ after it is sent from lambda. This can be done by ║ | |
║ request(query params, body, variables) and ║ mapping templates which transforms the payload, as per ║ | |
║ response(status code, message) are done ║ the user customisations. API Gat |