I am currently trying to read my dynamodb table "saved_measurements" with the partition key "Name". I'm doing this through API Gateway Lambda proxy integration, and have tested my
event['pathParameters']['name']
to be working just fine so that shouldn't be the issue.
However, when I query my dynamodb table with my 'Name', the error appears.
{"message": "Internal server error"}
I have referenced many resources for querying dynamodb but nothing seems to work. I have also tried printing a example string within the response body like "yes" and it works with no issues. Only when I attempt to send my data in my response body do I meet that issue again.
What can I try to resolve this?
import json
import boto3
from boto3.dynamodb.conditions import Key, Attr
def lambda_handler(event, context):
client = boto3.resource('dynamodb')
table = client.Table('saved_measurements')
data = table.query(KeyConditionExpression=Key('Name').eq(event['pathParameters']['name']))
stuff = data.Items
response = {
"statusCode": 200,
"headers": {
"Content-Type": 'application/json',
"Access-Control-Allow-Origin" : "*",
"Access-Control-Allow-Headers" : "Content-Type",
"Access-Control-Allow-Methods": "OPTIONS,POST,GET"
},
"body": json.dumps(stuff),
"isBase64Encoded": False
}
return response