AWS Lambda & API Gateway

The body response of Lambda must output a format that is acceptable to AWS API Gateway.  An example NodeJS code with the appropriate callback will ensure a successful 200 OK response:


'use strict';

console.log('Loading function');

exports.handler = (event, context, callback) => {
    var responseBody = {
        "key3": event.queryStringParameters.key3,
        "key2": event.queryStringParameters.key2,
        "key1": event.queryStringParameters.key1
    };

    var response = {
        "statusCode": 200,
        "headers": {},
        "body": JSON.stringify(responseBody),
        "isBase64Encoded": false
    };
   
    // In order for AWS API Gateway to work, the response must
    // be in the format of the "response" variable as shown above.
    callback(null, response);
};

You can find more information from the sources below.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: