Skip to content

Instantly share code, notes, and snippets.

@girlcheese
Created April 4, 2017 19:17
Show Gist options
  • Save girlcheese/bc93f76cf5424c64e40276010a0a2ca1 to your computer and use it in GitHub Desktop.
Save girlcheese/bc93f76cf5424c64e40276010a0a2ca1 to your computer and use it in GitHub Desktop.
Basic AWS Lambda code for proxying via an AWS API Gateway
"use strict";
process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT'];
var handler = function(event, context, callback){
const query = event.queryStringParameters || {};
const eventParams = event.body ? JSON.parse(event.body) : {};
var data = {
results: [1,2,3],
success: true
};
// here's the object we need to return
const res = {
"statusCode": 200,
"headers": {},
"body": JSON.stringify(data) // body must be returned as a string
};
context.succeed(res); // we must use this callback to return to amazon api gateway
//callback(null, JSON.stringify(res, null, 2)); // this does not work with the api
};
exports.handler = handler;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment