In the Serverless framework built with AWS, when a function is kept as
async: true
it immediately returns a 200 HTTP response, can we override this status codes. Can somebody answer to this thanks
I have tried to return response objects in multiple ways but the statusCode is always set to 200
return {
statusCode: 400
}
What you are asking for doesn't make sense. The whole purpose of invoking a function asynchronously is to invoke it and let it run without waiting for the response. The code you are changing runs at some time after you get that 200
response code.
The Lambda function isn't returning the response from an async call, the AWS Lambda service is returning that response. The service is letting you know it has started to invoke your Lambda function. Why would you want a 400
error code to be returned from that scenario?
If you care about the Lambda function's response code, you can't call it asynchronously, you have to call it synchronously, so that you wait for the function to actually run and return a response to you.