I am encountering an issue while running my API locally which invokes my GET Lambda function. Specifically, I am receiving a 502 bad gateway error and an error message saying 'Invalid lambda response received: Lambda response must be valid JSON' even after verifying that my JSON is valid using a JSON validator. Despite trying different solutions, I am still unable to resolve the issue.
def lambda_handler(event, context):
response = table.get_item(Key={'ID': 'viewCount'})
if "Item" in response:
view_count = response['Item']['viewCount']
print(view_count)
return {
"statusCode": 200,
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"Access-Control-Allow-Credentials": "*",
"Content-Type": "application/json",
"Access-Control-Expose-Headers": "*"
},
"body": view_count
# "body": "Something is def wrong"
# "body" : str(view_count)
}