Skip to content

Commit

Permalink
Add logging to lambda_handler to return request body useful for debug…
Browse files Browse the repository at this point in the history
…ging.
  • Loading branch information
niccolozanotti authored Sep 5, 2024
1 parent e4fc2bb commit 9d67790
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lambda_function.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
from flask import Flask, request
from flask_cors import CORS
import boto3
Expand Down Expand Up @@ -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)
app.run(debug=True)

0 comments on commit 9d67790

Please sign in to comment.