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
'use strict'; | |
const AWS = require('aws-sdk'); | |
// Set the Region | |
AWS.config.update({ | |
accessKeyId: '***********', | |
secretAccessKey: '*************', | |
region: 'us-east-1', | |
signatureVersion: 'v4' |
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: |
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. |
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); | |
}; |
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 |
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', | |
}), | |
}; |
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, | |
}), |
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 ║ |
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 |
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. ║ |