Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete amazon cognito user?

I want to delete cognito user using my nodejs application.
Example

cognitoUser.deleteUser (err, result) ->
  if err
    reject err
  resolve result

when i try to delete cognito user error throws as follows

Error: User is not authenticated

cognitoUser.deleteUser is used by an authenticated user to delete himself but i want to delete all users using super user

Please give me some idea to solve this problem.

like image 381
Richardson. M Avatar asked Jun 20 '17 05:06

Richardson. M


People also ask

How do I delete an unconfirmed user on Cognito?

You can delete the unconfirmed users by calling a lambda function every 7 days using CloudWatch event trigger. In the lambda function you can use listUsers api to list all the cognito users and adminDeleteUser api to delete the unconfirmed users.

How do I change my Cognito user?

You can't change standard user pool attributes after a user pool is created. Instead, create a new user pool with the attributes that you want to require for user registration. Then, migrate existing users to the new user pool by using an AWS Lambda function as a user migration trigger.

Can Cognito username be changed?

The user name is a fixed value that users can't change. If you mark an attribute as an alias, users can sign in with that attribute in place of the user name. You can mark the email address, phone number, and preferred username attributes as aliases.

What is AWS Cognito user?

Amazon Cognito lets you easily add user sign-up and authentication to your mobile and web apps. Amazon Cognito also enables you to authenticate users through an external identity provider and provides temporary security credentials to access your app's backend resources in AWS or any service behind Amazon API Gateway.


1 Answers

You can use the main aws javascript SDK and call the adminDeleteUser operation. It is an authenticated operation and it will require developer credentials for you to call it.

https://github.com/aws/aws-sdk-js/blob/master/apis/cognito-idp-2016-04-18.normal.json#L100

var aws = require('aws-sdk');
var CognitoIdentityServiceProvider = aws.CognitoIdentityServiceProvider;
var client = new CognitoIdentityServiceProvider({ apiVersion: '2016-04-19', region: 'us-east-1' });

//now you can call adminDeleteUser on the client object     
like image 54
Ionut Trestian Avatar answered Nov 15 '22 21:11

Ionut Trestian