title: How to delete the Cognito user in Node.js?
body: <p>How to delete user account from * cognito * in nodejs.</p>
  
  <p>I'm trying to delete the user from <em>cognito</em> it is not working for me.</p>
  
  <p><strong>AWS config</strong></p>
  
  <p><code>const AWS = require('aws-sdk');
  const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
  </code></p>
  
  <p><strong>Pool config</strong></p>
  
  <p><code>const poolConfig = {
      UserPoolId: keys.cognito.userPoolId,
      ClientId: keys.cognito.clientId
  };</code></p>
  
  <p>Above configurations comes on top of below delete function.</p>
  
  <p><em>Delete Function</em></p>
  
  <pre><code>function deleteUserFunc(req, decodedToken) {
      return new Promise((resolve, reject) =&gt; {
          const decodedEmailid = decodedToken.email;
          const decodedSub = decodedToken.sub;
          try {
                  const userDetails = { Username: decodedSub, Pool: userPool };
                  console.log('DEBUG : ' + JSON.stringify(userDetails));
                  const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userDetails);
  
                  // Attempting to delete the user
  
                  cognitoidentityserviceprovider.adminDeleteUser({
                      UserPoolId: keys.cognito.userPoolId,
                      Username: decodedEmailid
                      }, (err, data)=&gt;                              
                          if(err) {
                          return reject({
                              error: err.message
                          });
                          } else {
                          return resolve({
                              error: null
                          });
                          }
                      }).promise().catch(err=&gt;{
                      return reject({
                          error: err.message
                      });
                      });
  
                  console.log('User deleteion status : ' + result);
  
                  return resolve({
                      error: null,
                  });
              });
          } catch (err) {
              return reject({
                  error: err,
              });
          }
      });
  }
  
  </code></pre>
  
  <p>I have also tried to delete the user with 
  <code>const userDetails = { Username: decodedEmailId, Pool: userPool }</code> but no use.</p>
  
  <p>Any help will much appreciated.</p>