I am trying to write a serverless back-end for an application with AWS Lambda, and am running into the error in the title. The error occurs when testing with API Gateway proxy integration, but the function works fine when tested in the Lambda console.
Here is the error:
{
"errorMessage":"string indices must be integers",
"errorType":"TypeError",
"stackTrace":[
[
"/var/task/auth_login.py",
17,
"lambda_handler",
"response = get_user(payload)"
],
[
"/var/task/shifty_utils/__init__.py",
22,
"get_user",
"table = dynamo.Table(user['company'] + '_users')"
]
]
}
Here is context for where it occurs:
def lambda_handler(event, context):
payload = event['body']
response = get_user(payload)
def get_user(user):
try:
table = dynamo.Table(user['company'] + '_users')
response = table.get_item(
Key={
'userId': user['userId'],
'position': user['position']
}
)
except ClientError as e:
print(e.response['Error']['Message'])
return {'message': e.response['Error']['Message']}
else:
return response
Basically proxy integration seems to be reading in the event object as a JSON formatted string, as opposed to a dict, but here's what happens if I adjust my code for that:
{
"errorMessage":"the JSON object must be str, bytes or bytearray, not 'dict'",
"errorType":"TypeError",
"stackTrace":[
[
"/var/task/auth_login.py",
15,
"lambda_handler",
"payload = json.loads(event)"
],
[
"/var/lang/lib/python3.6/json/__init__.py",
348,
"loads",
"'not {!r}'.format(s.__class__.__name__))"
]
]
}
I can't win. Any help is appreciated.