Last active
April 20, 2018 20:58
-
-
Save WaleedAshraf/67a81e0fba32a4f13236dbfdc3f3b256 to your computer and use it in GitHub Desktop.
Building you first Serverless app in Node.js with AWS Lambda + S3 + API Gateway
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
exports.handler = async (event) => { | |
const operation = event.queryStringParameters ? event.queryStringParameters.operation : null; | |
let data = JSON.parse(event.body); | |
switch (operation) { | |
case 'ping': | |
return sendRes(200, 'pong'); | |
case 'convert': | |
return await operate(data); | |
default: | |
return sendRes(401, `Unrecognized operation "${operation}"`); | |
} | |
}; | |
const sendRes = (status, body) => { | |
var response = { | |
statusCode: status, | |
headers: { | |
"Content-Type": "text/html" | |
}, | |
body: body | |
}; | |
return response; | |
}; | |
const operate = async (body) => { | |
return sendRes(200, 'convert is called'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment