My API gateway functions use aws_iam security. Using Postman I can setup the security and call my API gateway function. The lambda function is being called and it generates a cloudwatch log. Inside the lamdba function I try to access: context.identity.cognitoIdentityId. This fails because context.identity is null. I also tried checking “Invoke with caller credentials” on my function in APIGateway - does not help.
So how do I get cognitoIdentityId from the lambda function?
Good question, @jonsmirl. I don’t think the AWS docs are clear on this.
The context object you’re referring to there is actually included within the event object under a key of requestContext. Thus, to get the context.identity.cognitoIdentityId, you’ll need to access event.requestContext.identity.cognitoIdentityId.
It’s hard to find this in the AWS docs, so I usually go to the Serverless docs here to see an example event from API Gateway.
Can you let me know if that works for you? If it doesn’t, can you let me know the integration type you’re using for API Gateway (e.g. lambda-proxy, http, http-proxy)?