Lambda with api gateway lambda_proxy integration error response

0

Hi!. I succesfully achieve to make lambda returning status code 400 and a message to the client. But in cloudwatch logs that execution even if i return status code 400 its returned like a success execution. I want to be able to "mark" that execution as an error and return the client a corresponding message with status code 400.
This is how i am returning the error

console.error(err);
response = {
'statusCode': 400,
headers: {

            "Access-Control-Allow-Origin": "*",  
        },  
        'body': 'Error al obtener productos'  
    }  

return response;  

Thanks in advance.
Pamela

pamtru
已提問 4 年前檢視次數 374 次
4 個答案
0

Are they not showing up as "4XXError" apigateway cloudwatch metrics?

Ellison
已回答 4 年前
0

Hi Ellison! Sry for the late response. No they arent the metrics all showing all as successfully execution.

Thanks!

pamtru
已回答 4 年前
0

perhaps I should clarify, the metrics for the lambda should always show as successful, unless it crashes with an uncaught exception or something like that. The apigateway metrics are where you'd want to be looking for the different response codes.

Ellison
已回答 4 年前
0

Thank you very much Ellison, i was looking the metrics for the lambda function and not in the api gateway. In the api metrics i can see the 400 errors.

Greetings!

pamtru
已回答 4 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南