I have a Lambda function handling POST requests triggered by the API Gateway. The latter is set up to authorize via a Cognito user pool authorizer. Authorization works - i
It depends on if you have Use Lambda Proxy Integration
selected in the Integration Request
for the lambda. If you have it set then all the token's claims will be passed through on event.requestContext.authorizer.claims
.
If you are not using Lambda Proxy Integration then you need to use a Body Mapping Template
in the Integration Request
for the lambda. An example template with the application/json
Content-Type is:
"context" : {
"sub" : "$context.authorizer.claims.sub",
"username" : "$context.authorizer.claims['cognito:username']",
"email" : "$context.authorizer.claims.email",
"userId" : "$context.authorizer.claims['custom:userId']"
}
This is expecting that there is a custom attribute called userId in the User Pool of course, and they are readable by the client.
You cannot use the id token against the aws cognito-idp APIs, you need to use the access token. You can however use AdminGetUser call with the username, if your lambda is authorized.