Site icon The Perpetual Student

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.

Exit mobile version