CCCC
CCCC

Reputation: 6471

aws - is it possible to use Cognito user pool custom field in lambda function?

I have created a custom field "permissions" in my user pool.
enter image description here enter image description here

I wonder if it is possible to use this field in my lambda function, so that I can do some permission control for calling the corresponding lambda function.

For example

if((**custom.permissions**).includes("admin")){
   // execute the lambda function
}

Upvotes: 1

Views: 527

Answers (1)

Asri Badlah
Asri Badlah

Reputation: 2123

For example if your lambda function was written using python boto3 you can get the user Attributes like this:

import boto3

client = boto3.client('cognito-idp')

response = client.get_user(
    AccessToken='string'
)

The response structure contains UserAttributes (list) -- An array of name-value pairs representing user attributes.

For custom attributes, you must prepend the custom: prefix to the attribute name.

Upvotes: 1

Related Questions