Skip to content

Commit

Permalink
✨ add custom serializer for Decimal types and log received events in …
Browse files Browse the repository at this point in the history
…lambda handlers
  • Loading branch information
LokoMoloko98 committed Jan 25, 2025
1 parent c1bbc22 commit 137e2c9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion swift-lift-fare-calculation/swift-lift-fare-calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def lambda_handler(event, context):
}
try:
print("Processing")

print(f"Received event: {json.dumps(event, indent=4, default=custom_serializer)}")
# Extract passenger_id and total trips from the event
passenger_id = event.get('passenger_id')
target_week = event.get('target_week')
Expand Down
6 changes: 6 additions & 0 deletions swift-lift-trips-table-ops/swift-lift-trips-table-ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
trips_table_name = "Swift-lift-club-portal-trips"
trips_table = dynamodb.Table(trips_table_name)

def custom_serializer(obj):
if isinstance(obj, Decimal):
return float(obj) # Convert Decimal to float
raise TypeError(f"Type {type(obj)} not serializable")

def generate_trip_date_time():
"""
Generate the current date and time in Central African Time (UTC+2) in ISO 8601 format.
Expand Down Expand Up @@ -62,6 +67,7 @@ def lambda_handler(event, context):
headers = {
"Content-Type": "application/json"
}
print(f"Received event: {json.dumps(event, indent=4, default=custom_serializer)}")

try:
print("Processing operation for trips table")
Expand Down

0 comments on commit 137e2c9

Please sign in to comment.