Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda Cognito User Pool authorizer - can I automatically get the custom user attributes?

I'm using Lambda functions, executed via API Gateway using a Cognito User Pool Authorizer.

I know I can get the "standard" user attributes (like sub, email, cognito:username, etc.) from event.requestContext.authorizer.claims.

But this does not include custom user attributes (like custom:myAttribute).

I know I can get them via adminGetUser, and this works, but I wonder whether I can save this call and somehow get those custom attributes automatically in the event?

like image 758
thomers Avatar asked Mar 10 '23 18:03

thomers


1 Answers

Have you already looked at this doc for custom claims? https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-enable-cognito-user-pool.html. You will need to define context in following manner for custom attributes:

{
    "context" : {
        "role" : "$context.authorizer.claims['custom:myAttribute']"
    }
}
like image 70
Vinay Kushwaha Avatar answered Apr 06 '23 07:04

Vinay Kushwaha