0 votes
1 view
in AWS by (18.1k points)

For instance, if I want to return a specific 400 error for invalid parameters or perhaps a 201 when the lambda function call resulted in a create.

I'd like to have different http status codes but it looks like API gateway always returns a 200 status code even if the lambda function is returning an error.

1 Answer

0 votes
by (42.2k points)

Lambda Proxy Integration is allowed now, and because of that the Lambda function can return proper HTTP codes and headers:

let response = {

    statusCode: '400',

    body: JSON.stringify({ error: 'What up!' }),

    headers: {

        'Content-Type': 'application/json',

    }

};

context.succeed(response);

The second option is to integrate aws-serverless-express with an already existing Express app with Lambda/API gateway.

...