From 9d677907d4cd093261550d2beefd8254084ac3a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Zanotti?= <74741715+niccolozanotti@users.noreply.github.com> Date: Thu, 5 Sep 2024 17:33:13 +0200 Subject: [PATCH] Add logging to lambda_handler to return request body useful for debugging. --- lambda_function.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lambda_function.py b/lambda_function.py index 9e0bfa4..a5d2482 100644 --- a/lambda_function.py +++ b/lambda_function.py @@ -1,4 +1,5 @@ import json +import logging from flask import Flask, request from flask_cors import CORS import boto3 @@ -88,12 +89,23 @@ def append_log_to_s3(log_entry): # Upload the updated log file back to S3 s3.upload_file(log_file, BUCKET_NAME, LOG_FILE_KEY) +# Configure logging +logger = logging.getLogger() +logger.setLevel(logging.INFO) # AWS Lambda handler def lambda_handler(event, context): + # Log the full event (this includes the request body and other information) + logger.info(f"Received event: {json.dumps(event)}") + + # Log only the request body (if present) + if 'body' in event: + logger.info(f"Request body: {event['body']}") + + # Call the response function (assuming it's part of your application logic) return response(app, event, context) # For local testing if __name__ == '__main__': - app.run(debug=True) \ No newline at end of file + app.run(debug=True)