Here is my code snipped that retrieves data from customer-event-logs dynamoDB table with customer_id parameter from /events endpoint.
elif path == '/events':
# Handle the /events endpoint logic here
request_json = event['body']
request_data = json.loads(request_json)
# Extract the customer-id from the request data
customer_id = request_data.get('customer-id', 'default_customer_id')
# Check if the customer-id exists in the customers table
if not check_customer_exists(customer_id):
return {
"statusCode": 400,
"body": json.dumps({"error": "Customer ID does not exist."})
}
# Query the customer-event-logs table for records associated with the customer_id
try:
table = dynamodb_resource.Table('customer-event-logs')
response = table.scan(
FilterExpression=Attr('customer_id').eq(customer_id)
)
event_logs = response.get('Items', [])
except Exception as e:
return {
"statusCode": 500,
"body": json.dumps({"error": "Failed to retrieve event logs."})
}
return {
"statusCode": 200,
"body": json.dumps(event_logs)
}
There are plenty of record in my customer-event-logs table with 'customer123' however this code returns me always {"error": "Failed to retrieve event logs."} message.
I gave my Lambda function full access to this dynomoDB table.
Is there any idea to solve this issue?