in lambdas/api_post_reviews/index.py [0:0]
def lambda_handler(event, context):
status_code = 400
try:
# print("[DEBUG] Received event: " + json.dumps(event, indent=2))
user_id = event['requestContext']['identity']['cognitoIdentityId']
input = json.loads(event['body'])
input['user_id'] = user_id
input['create_date'] = str(datetime.utcnow())
print('[DEBUG] Received input: ' + json.dumps(input))
table.put_item(Item=input)
output = '[SUCCESS] Review posted successfully.'
status_code = 200
except Exception as e:
print('ERROR: ', e)
output = '{}'.format(e)
# Construct API response
response = {
'statusCode': status_code,
'headers': {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': True,
'Access-Control-Allow-Headers': 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS,HEAD,PATCH',
'Content-Type': 'application/json'
},
'body': json.dumps(output)
}
print('[INFO] Query response: {}'.format(json.dumps(response)))
return response