Skip to content

Instantly share code, notes, and snippets.

@WaleedAshraf
Last active April 20, 2018 20:58
Show Gist options
  • Save WaleedAshraf/67a81e0fba32a4f13236dbfdc3f3b256 to your computer and use it in GitHub Desktop.
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
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