Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.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 (44.4k 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.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

Browse Categories

...