4xxCount and 5xxCount are not found for my Lambda function URL with stream

0

I made and have used Lambda function url with stream feature on NodeJS runtime. On Cloudwatch, I can't find 4xxCount and 5xxCount invocation metrics, which will be helpful to alarm errors. I even tried throwing a new Error('test') in my lambda and found the error log in my log group, but I didn't see any corresponding error metrics incremented, nor did the 4xxCount and 5xxCount metrics show up.

References Monitoring Lambda function URLs https://docs.aws.amazon.com/lambda/latest/dg/urls-monitoring.html

gefragt vor 2 Monaten218 Aufrufe
1 Antwort
0

Hello.

You can now check CloudWatch metrics by setting the response status code to "400" or "500" and making a request to the function URL as shown below.

export const handler = async (event) => {
  // TODO implement
  const response = {
    statusCode: 400,
    body: JSON.stringify('Hello from Lambda!'),
  };
  return response;
};

a

profile picture
EXPERTE
beantwortet vor 2 Monaten
  • Thanks for the prompt answer. Let me clarify a few things:

    • A developer shouldn't throw an error? Should they always catch an error and return some response to increment an alarm?
    • Is your answer valid for streaming? It seems a bit different as a streaming sample[1] let you directly responseStream.write your response chunk message. Also, my code below didn't trigger an alarm.
    exports.handler = streamifyResponse(async (event, responseStream, context) => {
      responseStream.write({statusCode: 500, body: 'this is 500'})
    })

    [1] Configuring a Lambda function to stream responses https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html

    PostScript: I tried the code below from doc[2], but it didn't increemnt `Url5xxCount'

                        const metadata = {
                        statusCode: 500,
                        headers: {
                            "Content-Type": "application/json",
                            "CustomHeader": "outerspace"
                        }
                        };
                        responseStream = awslambda.HttpResponseStream.from(responseStream, metadata);
                        responseStream.write("Error!");

    [2] https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/response-streaming-tutorial.html

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen