Lambda's logs(CloudWatch) are always lost.

0

When I test my lambda function, I found some log not exist in CloudWatch. Sometimes logs are recorded, and sometimes they are not. How should I troubleshoot this issue?

Follows are the screenshot of my Lambda and the lost log. The lost log is from 10:07:39 to 10:24:51. I can confirm that the lambda is running during this period. This is just one of the many lost logs, and other time points will also frequently lose logs.

Lambda Information

Log List

Log1

Log2

asked 9 days ago135 views
3 Answers
4

hlo,

Please follow once below mentioned procedure.

1.Check Lambda Execution: First, ensure that your Lambda function is indeed executing during the period when logs are missing. You can do this by checking the CloudWatch Logs for invocations of your Lambda function during the specified timeframe.

  1. Review CloudWatch Log Groups: Verify that your Lambda function is configured to send logs to the correct CloudWatch log group. Sometimes, misconfigurations can result in logs being sent to the wrong log group or not being sent at all.

3.Check Lambda Configuration: Review the configuration of your Lambda function, including its logging settings. Ensure that logging is enabled and configured correctly, including the log group name and log retention settings.

4.Inspect Lambda Function Code: Examine your Lambda function code to ensure that logging statements are correctly implemented and are not being skipped or suppressed under certain conditions.

  1. Check for Errors: Look for any errors or warnings in your Lambda function's execution that might indicate issues with logging. Check for exceptions or errors that could prevent logging from occurring properly.

6.Verify IAM Permissions: Ensure that the IAM role associated with your Lambda function has the necessary permissions to write logs to CloudWatch Logs. Verify that the role has permissions for the logs:CreateLogGroup, logs:CreateLogStream, and logs:PutLogEvents actions.

7eview CloudWatch Logs Metrics: Check the CloudWatch Logs metrics to see if there are any indications of throttling or other issues with log ingestion during the timeframe when logs are missing.

Contact AWS Support: If you're unable to resolve the issue after investigating the above steps, consider reaching out to AWS Support for assistance. They can help you troubleshoot and diagnose any underlying issues with CloudWatch Logs or your Lambda function configuration.

answered 9 days ago
  • Thanks for you reply.

    1. I'm testting the lambda, so there will only be one call at a time.
    2. There are logs in CloudWatch, so the permission are correct.
    3. The first line of my lambda code is write the log. so no matter what, as long as the lambda runs, it will definitely be recorded in the log.
    4. I can confirm that the lambda is running during the period of lost log.
  • 1.Execution Time: Is it possible that the Lambda function is completing so quickly during those periods that the logs are being written and flushed before you have a chance to observe them? You can try adding some additional logging throughout your code to see if any other logs are being recorded.

    2.Log Retention Settings: Double-check the log retention settings in CloudWatch Logs to ensure that logs are being retained for a sufficient period. If the retention period is too short, logs may be getting automatically deleted before you're able to review them.

    3.Concurrency Limit: Although you mentioned there will only be one call at a time, it's worth verifying that you're not hitting any concurrency limits that could be causing some executions to be throttled.

    4.Error Handling: Check for any potential errors or exceptions in your Lambda function that might be causing it to terminate prematurely without writing the expected logs. Even if the Lambda function is running, if it encounters an unhandled error, it may not produce the expected output.

    5.Cold Starts: Cold starts can sometimes behave differently from warm starts, so ensure that you're considering this aspect. During a cold start, there might be some delay before the logs start appearing.

    6.CloudWatch Logs Latency: In rare cases, there might be latency or issues with CloudWatch Logs itself that could result in delayed or missing logs. Keep an eye on AWS Service Health Dashboard for any reported issues.

    1. I can make sure the lambda is triggered, and it works fine. I can obtain its running results, but there isn't any log in CloudWatch.
    2. Logs lose data every day.
    3. Lambda is currently in development, only I am testing it and no one else is using it. So I can confirm that there will be no concurrency.
    4. Several minutes of data are often lost in the logs. For example: lost 17 minutes logs. The log has been lost for too long, and I don't know why it was lost for such a long time.
1

Consider these following reasons to check it once

=>Check Invocation Metrics: Look for any unusual patterns or drops in the invocation count of your Lambda function.

=>Verify Function Configuration: Ensure that your Lambda function is configured correctly, especially its logging settings and permissions.

=>Review Timeout Settings: Check if the function's execution time exceeds the configured timeout, which could prevent logs from being written.

=>Inspect Function Code: Review the function code for errors or issues that may cause it to terminate prematurely or fail to log properly.

=>Check CloudWatch Log Group: Manually inspect the CloudWatch log group associated with your Lambda function to see if the missing logs are present.

=.Verify Log Retention Settings: Ensure that logs are not being deleted due to retention policies set in CloudWatch.

=>Review Invocation History: Look for any errors or warnings in the Lambda function invocation history that may indicate execution issues.

=>Consider Enhanced Monitoring: Enable enhanced monitoring for your Lambda function to gather additional insights into its performance.

answered 9 days ago
  • Thanks for you reply.

    1. I'm testting the lambda, so there will only be one call at a time.
    2. There are logs in CloudWatch, so the permission are correct.
    3. The first line of my lambda code is write the log. so no matter what, as long as the lambda runs, it will definitely be recorded in the log.
    4. I can confirm that the lambda is running during the period of lost log.
0

There are several reasons why your Lambda function's logs might be missing from CloudWatch even though the function is running. Here's how to troubleshoot the issue:

Review IAM Permissions: Double-check your IAM role or policy and ensure it has logs:PutLogEvents permission on the CloudWatch log group.

Verify Log Group Configuration: Confirm the Lambda function is configured to use the correct CloudWatch log group in the "Monitoring" tab.

Consider Cold Starts: If applicable, explore ways to keep your function warm to minimize log loss during cold starts.

Investigate Batching: Experiment with adjusting AWS_X_RAY_LOGGING_BUFFER_SIZE if log latency is critical. Remember the cost implications.

Monitor Throttling: Check CloudWatch Logs metrics for throttling events if you suspect high invocation rates might be causing issues.

answered 9 days ago

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