-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcognito_listAllUsers.js
More file actions
46 lines (42 loc) · 1.33 KB
/
Copy pathcognito_listAllUsers.js
File metadata and controls
46 lines (42 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
var fs = require('fs');
// var data = require ( './cognito-user-list-201904261342.json' );
const AWS = require ( 'aws-sdk' );
var counter = 1;
const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider({ region: 'eu-west-1',});
var params = {
UserPoolId: '', /* required */
AttributesToGet: [
'email',
/* more items */
],
Limit: '0',
//PaginationToken: 'pages60'
};
const listThemAll = async (params) => {
return new Promise((resolve,reject) => {
cognitoidentityserviceprovider.listUsers(params, function(err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
reject (err);
} else {
fs.writeFile(`result_${counter}.json`, JSON.stringify(data, null, 2), (err)=>{
console.log ( data.PaginationToken );
if(data.hasOwnProperty('PaginationToken')) {
resolve (data.PaginationToken);
} else {
resolve(null);
}
});
}
});
});
};
async function getAll() {
let pagination_token = null;
do {
let _params = Object.assign({}, params, {PaginationToken: pagination_token});
pagination_token = await listThemAll(_params);
} while( pagination_token !== null );
}
getAll();