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

asked 2 months ago209 views
1 Answer
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
EXPERT
answered 2 months ago
  • 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

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions