1const AWS = require('aws-sdk');
2const cognitoIdentity = new AWS.CognitoIdentityServiceProvider({ region: 'us-east-1' }); //replace with the region of your user pool
3
4const UserPoolId = process.env.UserPoolId;
5
6exports.handler = async (event) => {
7 const { idToken } = event;
8
9 //TODO: validate and decode idToken
10 //https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-verifying-a-jwt.html
11
12 const Username = decodedIdToken["cognito:username"];
13
14 const deleteParams = {
15 Username,
16 UserPoolId
17 }
18
19 try {
20 const result = await cognitoIdentity.adminDeleteUser(deleteParams).promise();
21 return result;
22 } catch (e) {
23 console.log(`error deleting user ${Username}: ${e}`)
24 throw e;
25 }
26}
27