For a web app, I am making an AWS Lambda function which is triggered by the api gateway. I have the api gateway linked to a cognito user pool so you need to sign in before triggering the function. The "Options" part has no authorization enabled and the "post" method has the cognito user pool as the authorizer. When I press a button on the front end to trigger it, the function runs correctly. My problem is that context.identity.cognito_identity_id always returns a null value and not a sub uuid as expected. I don't know why this is. I tried enabling "Invoke with caller credentials" but when I mouse over the check box is says I can't enable it. This is my current lambda function:
import json
def lambda_handler(event, context):
UniqueUser = context.identity.cognito_identity_id
if not UniqueUser:
UniqueUser = "fail"
return {
'statusCode': 200,
'headers': {
'Access-Control-Allow-Origin': '*'
},
'body': json.dumps('Hello from Lambda ' + UniqueUser + "!")
};
How can I make it so that context.identity.cognito_identity_id (or something similar) returns the user's uuid as I believe it should?