Skip to content

Amazon Cognito to Keycloak user converter

Turn Amazon Cognito users, as a CSV with Cognito’s attribute names or as list-users JSON, into a Keycloak import file with custom attributes and groups.

Runs in your browser. Nothing you paste is sent to us.

Cognito export

A CSV with Cognito attribute names as the header, or the JSON of aws cognito-idp list-users. Made-up users are filled in. It stays in your browser.

Falls back to the other when a user has none. Usernames are written in lower case.

Cognito lists groups apart from users. Add a groups column (from admin-list-groups-for-user) and name it here, or leave it empty.

Output

Keycloak users

3 users 2 set a new password 1 sign in with a provider

Records read
3
Users in the file
3
Left out
0
Set a new password by email link
2Marked with the Update Password required action
Social or enterprise sign-in only
1Re-link by email at their first sign-in
Disabled in the source
0
In groups
2/staff, /staff/support
Attributes
3cognito_sub, department, phone_number
Password hashes left out
0Keycloak cannot verify them, so the file never holds them
JSON
{
  "groups": [
    {
      "name": "staff",
      "subGroups": [
        {
          "name": "support",
          "subGroups": []
        }
      ]
    }
  ],
  "users": [
    {
      "username": "[email protected]",
      "email": "[email protected]",
      "emailVerified": true,
      "firstName": "Sample",
      "lastName": "One",
      "enabled": true,
      "attributes": {
        "phone_number": [
          "+15555550101"
        ],
        "department": [
          "Sales"
        ],
        "cognito_sub": [
          "00000000-0000-4000-8000-000000000001"
        ]
      },
      "groups": [
        "/staff"
      ],
      "requiredActions": [
        "UPDATE_PASSWORD"
      ]
    },
    {
      "username": "[email protected]",
      "email": "[email protected]",
      "emailVerified": true,
      "firstName": "Sample",
      "lastName": "Two",
      "enabled": true,
      "attributes": {
        "department": [
          "Support"
        ],
        "cognito_sub": [
          "00000000-0000-4000-8000-000000000002"
        ]
      },
      "groups": [
        "/staff/support"
      ]
    },
    {
      "username": "[email protected]",
      "email": "[email protected]",
      "emailVerified": false,
      "firstName": "Sample",
      "lastName": "Three",
      "enabled": true,
      "attributes": {
        "cognito_sub": [
          "00000000-0000-4000-8000-000000000003"
        ]
      },
      "requiredActions": [
        "UPDATE_PASSWORD"
      ]
    }
  ]
}
Read but not carried over
  • cognito:mfa_enabled, MFAOptions: MFA secrets are not in this export; users enroll again.
  • phone_number_verified: Keycloak has no verified flag for phone numbers.
  • identities: Used to tell federated users apart, then left out.
  • UserLastModifiedDate, updated_at: History does not move.
In the admin console: Realm settings, Action, Partial import. Choose Skip or Fail for users that already exist. Keycloak keeps only attributes its user profile declares, unless the realm allows unmanaged attributes: add them to the user profile first.

How to use it

  1. Export users with aws cognito-idp list-users, or build a CSV with Cognito’s attribute names.
  2. Add a groups column if you want groups, and name it here.
  3. Paste the data or open the file.
  4. Save the import file and test it on a staging realm.

What to know

Cognito does not export passwords or password hashes, so every password user sets a new password by email link after the move.

custom: attributes keep their name without the prefix. Users whose username starts with a provider name, such as Google_, are treated as federated and re-link by email.

Cognito’s CSV writes a comma inside a value as a backslash and a comma. The tool reads that, and quoted fields too.

Moving users from Amazon Cognito to Keycloak

A Cognito user pool holds users with a username, a set of standard attributes taken from OpenID Connect (email, given_name, family_name, phone_number and others), any custom attributes you added with the custom: prefix, a status and an enabled flag. Keycloak holds the same facts as a username, email, first and last name, attributes and an enabled flag.

This converter reads Cognito users in either of the two shapes people have: the JSON of aws cognito-idp list-users, or a CSV whose header uses Cognito’s attribute names, the same names as Cognito’s own import template. It writes a Keycloak partial import or realm import file, in your browser.

For the whole move, with the plan, the cut-over and what each of our plans covers, see moving from Amazon Cognito.

Getting users out of Cognito

Cognito has an import job for CSV files but no export job. To get users out, you list them through the API. list-users returns up to 60 users per page with a pagination token; the AWS CLI follows the token for you.

All users of a pool, as JSON
aws cognito-idp list-users --user-pool-id <pool-id> --output json > users.json

Each user comes back with Username, Attributes as a list of name and value pairs, Enabled, UserStatus, UserCreateDate, UserLastModifiedDate and, for older pools, MFAOptions. There is no password, no hash and no group list.

Groups are listed per user with admin-list-groups-for-user, or per group with list-users-in-group. If you want groups in Keycloak, collect them with a short script and add a groups column to a CSV, with several names separated by semicolons. The tool turns them into group paths.

AWS publishes a reference architecture for exporting Cognito user profiles and groups. Its own limits say it does not export sensitive information such as passwords, and that it does not support pools with MFA turned on.

Why passwords do not move

Cognito does not give out passwords or password hashes. The list-users response has no field for them, and AWS’s own export guidance names passwords as data it does not export. Cognito can import hashes from other systems, but nothing comes back the other way.

So every Cognito user who signs in with a password sets a new one after the move. The tool marks them with Keycloak’s UPDATE_PASSWORD required action. After the import, an admin or a script sends each of them a set-password link with Keycloak’s execute-actions-email endpoint.

Users who sign in through a social or SAML provider are different. Cognito names them after the provider, such as Google_1000…, and gives them the status EXTERNAL_PROVIDER. The tool treats them as federated: no password step, and a link to their account by email at their first sign-in through the same provider in Keycloak.

What the tool does with each field

CognitoKeycloak userNotes
emailemail, in lower caseAlso the username by default
email_verifiedemailVerifiedTRUE or true both work
given_name, family_namefirstName, lastNameFrom name when both are empty
cognito:username or Usernameusername when you choose the id
subThe cognito_sub attributeThe id your apps saw in tokens
EnabledenabledMissing means enabled
UserCreateDatecreatedTimestampSeconds become milliseconds
custom:<name>The <name> attributeWithout the prefix
phone_number, locale, zoneinfo and other standard onesAttributes of the same name
A groups column you addgroups, as paths

Read and left out: cognito:mfa_enabled and MFAOptions, phone_number_verified (Keycloak has no verified flag for phone numbers), identities, and the modification dates.

The CSV format

Cognito’s import CSV does not quote values. A comma inside a value is written as a backslash and a comma, so 1 Sample Street\, Sample Town is one address. The tool reads that, and quoted fields as spreadsheets write them. Column order does not matter, and empty cells are skipped.

The sub and your app data

Apps often store Cognito’s sub as the key for a user’s data, because it is the subject of Cognito’s tokens. Keycloak gives each user its own id, so the subject changes after the move. Keep cognito_sub as an attribute, and either look users up by it on their first sign-in, or add a token mapper so the token carries it under a claim your app reads.

The output

Sample output for one made-up user
{
  "users": [
    {
      "username": "[email protected]",
      "email": "[email protected]",
      "emailVerified": true,
      "firstName": "Sample",
      "lastName": "One",
      "enabled": true,
      "attributes": {
        "phone_number": ["+15555550101"],
        "department": ["Sales"],
        "cognito_sub": ["00000000-0000-4000-8000-000000000001"]
      },
      "groups": ["/staff"],
      "requiredActions": ["UPDATE_PASSWORD"]
    }
  ]
}

The preview shows the first 20 users; the saved file has every user. With groups on, the file lists the group tree too, so partial import creates the groups first.

Lambda triggers and app clients

Cognito pools often carry logic in Lambda triggers: pre sign-up checks, custom messages, token claims added in a pre token generation trigger, or a user migration trigger. None of that moves on its own. List each trigger and decide its Keycloak counterpart: a required action, a client scope mapper for token claims, or a change in your app.

App clients become Keycloak clients. Re-create each one with its callback URLs, allowed scopes and whether it has a secret. Public clients that used the Cognito hosted UI move to Keycloak’s authorization code flow with PKCE. The PKCE generator and the client JSON builder help with that part.

Adding groups to the export

Because Cognito lists groups apart from users, most teams build the CSV in two passes: first the users from list-users, then one call per user for their groups. A small script does it; the one below uses the AWS CLI and jq, and writes the columns the converter reads.

Users with their groups, as a CSV (a sketch; add the attributes you use)
POOL=<pool-id>
echo "cognito:username,sub,email,email_verified,given_name,family_name,groups"
aws cognito-idp list-users --user-pool-id "$POOL" --output json \
  | jq -c '.Users[] | {u: .Username, a: (.Attributes | from_entries)}' \
  | while read -r row; do
      user=$(echo "$row" | jq -r .u)
      groups=$(aws cognito-idp admin-list-groups-for-user --user-pool-id "$POOL" \
        --username "$user" --query 'Groups[].GroupName' --output text | tr '\t' ';')
      echo "$row" | jq -r --arg g "$groups" \
        '[.u, .a.sub, .a.email, .a.email_verified, .a.given_name, .a.family_name, $g] | @csv'
    done

Run it from a machine with credentials that may read the pool, and keep the output file as private as the export itself.

One call per user is slow for a large pool, and Cognito limits how fast admin calls may run. For large pools, list each group’s members with list-users-in-group instead: one call per group and page, then join the two lists by username.

What your users see

Password users get one email from Keycloak with a link. It opens Keycloak’s Update Password page; they choose a password and are signed in. If the link has expired, Forgot password on the sign-in page sends a fresh one, as long as the realm allows it.

Users from Google or another provider see the provider button on Keycloak’s sign-in page. The first time, Keycloak tells them an account with their email exists and asks them to confirm the link, by email or by signing in. After that, sign-in is one click as before.

Everyone signs in once after the switch, because Cognito sessions and refresh tokens do not carry over. Apps that keep a Cognito refresh token for weeks should handle a failed refresh by sending the user to sign in.

The sign-in page changes too. Cognito’s hosted UI gives way to Keycloak’s own pages, in Keycloak’s standard theme, at your realm’s address. Custom themes are not supported on our clusters yet, so tell users the page will look different.

Mistakes to avoid

  • Waiting for a hash export from AWS. There is none: plan the set-password emails from the start.
  • Dropping sub and losing the link between users and your app’s data.
  • Treating Google_ users as password users. They would get a set-password email they do not need.
  • Forgetting the custom attributes in the realm’s user profile. Keycloak drops undeclared attributes.
  • Skipping the dry run. Import into a staging realm and sign in through each app first.

Where we come in

On Premium and Enterprise, our team does the move with you within the plan’s 10 service hours a month. On Starter, you use these tools and guides, with written support. Very large pools are scoped as a Custom plan through the contact form. The readiness checklist has every step for a Cognito move, and the email templates help you prepare your users.

Questions

Frequently asked questions

Can I export password hashes from Amazon Cognito?

No. The API returns no password data and AWS’s export guidance says passwords are not exported, so users set a new password by email link.

Which input should I use, CSV or JSON?

Either. The list-users JSON is the easiest to get; a CSV is handy when you add a groups column.

What happens to custom: attributes?

They become Keycloak attributes without the prefix, so custom:department becomes department.

Do users who sign in with Google need a new password?

No. The tool spots them by their provider prefix or status, and they link their account by email at their first sign-in.

Does MFA move from Cognito?

No. Cognito exports no TOTP secrets, so users set up their authenticator again in Keycloak.

How do I keep the link to my app data?

Keep the cognito_sub attribute and map it into tokens, or look users up by it on first sign-in.

Does the tool read the CSV made for Cognito’s import job?

Yes. The header names match Cognito’s CSV template, including cognito:username and cognito:mfa_enabled, and the backslash before a comma inside a value.

What about users who never confirmed their account?

They come across like other password users, usually with an unverified email. Leave them out of the file if you do not want them, or let them set a password and verify their email in Keycloak.

Is my data uploaded?

No. The conversion runs in your browser, and the saved file is made on your computer.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.