A simple CLI tool and JavaScript package for exporting users from an AWS Cognito user pool.
npm install cognito-export# Cognito Export
A simple CLI tool and JavaScript package for exporting users from an AWS Cognito user pool.
> This tool works perfectly with cognito-import. The user records exported match the import template to easily export from one user pool and import to another.
> Please be vigilant in deleting any local CSV files after use. This is how security leaks happen!
1. Use it as a CLI tool to export the users to a CSV file
npx cognito-export -u
2. or, use it in Node.js
npm i cognito-export
``typescript
import cognitoExport from "cognito-export";
const users = await cognitoExport({
userPoolId: "
});
`
> All flags and options can be found in the table below.
A full example of the CLI tool in effect can be found below:
npx cognito-export -u eu-west-1_aaaaaaaaa -p SOMEPROFILE -v
| Flag | Description |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| -u, --user-pool-id
| -p, --profile PROFILEA | The AWS profile to use for authentication. This will default to the AWS_PROFILE environment variable if left blank, or default if that is undefined. |./users.csv
| -o, --output ./users.csv | The path to the output CSV file. Defaults to . |1000
| -l, --limit 1000 | Limit the number of users outputted. Defaults to . |true
| -v, --verbose | Show all logs and errors in the console. Defaults to . |
| -h, --help | See all flags and options |
## 2. Node.js Example
A full example of the package in effect can be found below:
`typescript
import cognitoExport from "cognito-export";
const users = await cognitoExport({
userPoolId: "eu-west-1_aaaaaaaaa",
profile: "SOMEPROFILE",
});
`
> Please note: This method supports all flags documented above, except the output and help flags. Instead, the method returns the type-safe user records.
`bash`
npx cognito-export -u eu-west-1_aaaaaaaaa -p PROFILE_A &&
npx cognito-import -u eu-west-1_bbbbbbbbb -p PROFILE_B -f users.csv
or
`typescript
import cognitoExport from "cognito-export";
import cognitoImport from "cognito-import";
const users = await cognitoExport({
userPoolId: "eu-west-1_aaaaaaaaa",
profile: "PROFILE_A",
});
await cognitoImport(users, {
jobId: "import-12345",
userPoolId: "eu-west-2_bbbbbbbbb",
profile: "PROFILE_B",
}).start();
``