Manish Pal
Manish Pal

Reputation: 361

How to add a user in Cognito User Pool group?

Just started with Cognito User Pools. I am using the Python lambda function and boto3 to create users with the required fields. Now, I want to add users in a particular group using lambda. How to do the same? I created a group 'superadmin' in Cognito and using the below API.

response = client.admin_add_user_to_group(
    UserPoolId='user_pool_id',
    Username='testuser',
    GroupName='superadmin'
)

but I am getting the obvious error, NotAuthorizedException. How to pass developer credentials here?

Upvotes: 0

Views: 1064

Answers (1)

Ninad Gaikwad
Ninad Gaikwad

Reputation: 4480

Since you are using a lambda, the best practice would be to create a policy that allows you to add user to group and attach this policy to your lambda role. You do not need to pass developer credentials in a lambda as default lambda "credentials" are passed to your boto3 client for every call.

Upvotes: 1

Related Questions