I am using a custom authorizer for my aws serverless app.
I have a cognito user pool. The workflow I am trying to accomplish is
- Client signs in to cognito user pool
- Client gets token
id_token
to make future api calls - User hits a GET request on my getUserInfo api endpoint, passing along the token
- The lambda function uses the token to verify a) that the user is logged in, and b) that the user's token matches the
user_name
for which information is being requested
My understanding is that #4 can be accomplished by interrogating the context
object for an authorizer.principalId
attribute, based on this aws documentation.
However, when I test the endpoint, my context object in the python lambda does not contain this authorizer property.
The property dump for the context
object from CloudWatch is as follows:
{'aws_request_id': 'a37a1735-0ef3-*****-7fb1226218fe', 'log_group_name': '/aws/lambda/****', 'log_stream_name': '2019/01/03/[$LATEST]cca175ae1ff64cb699******', 'function_name': '*****getUser', 'memory_limit_in_mb': '1024', 'function_version': '$LATEST', 'invoked_function_arn': 'arn:aws:lambda:us-east-1:*********getUser', 'client_context': None, 'identity': <__main__.CognitoIdentity object at 0x7f1caf1bbdd8>}
My python lambda is of the form:
def getUser(event, context):
print(context)
print(context.__dict__)
print(context.authorizer)
print(context.identity.__dict__)
print(event.__dict__)
...
How can I make my lambda retrieve the required info so that I can verify the username from the incoming token?