-
Notifications
You must be signed in to change notification settings - Fork 100
Add cloudwatch_logs.py utility file to monitor lambdas #6740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Reorganized import statements for better clarity. - Standardized string formatting and spacing throughout the code. - Enhanced function definitions and comments for better understanding. - Improved error handling and logging for AWS interactions. - Updated README.md to remove unnecessary newline.
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
from typing import Any, Dict, List, Optional | ||
|
||
import boto3 # type: ignore[import-untyped] | ||
import dateparser # type: ignore[import-untyped] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of custom dependency to be frank..
if options.output_file: | ||
# Write to output file | ||
with open(options.output_file, "w", encoding="utf-8") as f: | ||
f.writelines(header) | ||
for log_content in all_logs: | ||
f.write(log_content) | ||
print(f"Downloaded logs to: {options.output_file}") | ||
else: | ||
# Write to stdout | ||
import sys | ||
|
||
sys.stdout.writelines(header) | ||
for log_content in all_logs: | ||
sys.stdout.write(log_content) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not combine this logic to something like
def write_logs(f):
f.writelines(header)
for log_content in all_logs:
f.write(log_content)
if options.output_file:
with open(options.output_file, "w", encoding="utf-8") as f:
write_logs(f)
else:
write_logs(sys.stdout)
except NoCredentialsError: | ||
print( | ||
"Error: AWS credentials not found. Please configure your AWS credentials." | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sys.exit(-1)
seems to be in order here
except ValueError as e: | ||
print(f"Error: {e}") | ||
except ClientError as e: | ||
print(f"AWS Error: {e}") | ||
except Exception as e: | ||
print(f"Unexpected error: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, what's the value of catching those errors? If script fails, it should fail and return non-zero status code, but right now it's not the case
Signed-off-by: Eli Uriegas <[email protected]>
This adds a cloudwatch_logs.py utility file in order to make it easier to debug lambdas if / when things go awry.
Example usage: