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

질문됨 2달 전218회 조회
1개 답변
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
전문가
답변함 2달 전
  • 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

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠