hawkerfun / cognito-csv-exporter

Amazon Cognito User Pool CSV exporter
105 stars 67 forks source link

Something else went wrong #12

Open gabrieldo02 opened 2 years ago

gabrieldo02 commented 2 years ago

I followed the steps exactly, but I keep getting "Something else went wrong." Were there bugs that were not fixed?

envisean commented 2 years ago

@gabrieldo02 I just setup this repo on my new m1 computer and I'm getting the same error response. It used to work for me on my old system, I'm not sure if things have changed since I also upgraded to AWS CLI 2

cwong-archy commented 1 year ago

same error which is not very helpful unfortunately. )=

$ python3 CognitoUserToCSV.py --user-pool-id  us-east-2_**** -attr Username
Something else went wrong

$ cat us-east-2_****.csv
Username
onurgokerlotec commented 1 year ago

I get the same error as well.

"Something else went wrong"

cwong-archy commented 1 year ago

because our cognito user pool fields are very simple, we ended up just using the aws cli. in this case, we only care about the email, name, and email_verified.

so we export the user to a csv file, make some changes, then import it via cognito import job.

here are the simple scripts we used to made this happen in case anyone find it useful.

export (there are some required field in order for cognito import job to work) -

#!/usr/bin/env bash

env="${1:-demo}"
pool=$(aws cognito-idp list-user-pools --max-results 20 | jq -r --arg env $env '.UserPools[] | select(.Name|test($env)) | .Id')
csv_file="/tmp/userpool-users.csv"
json_file="/tmp/${pool}-$$.json"
echo env $env
echo pool $pool
echo csv_file $csv_file

echo "name,given_name,family_name,middle_name,nickname,preferred_username,profile,picture,website,email,email_verified,gender,birthdate,zoneinfo,locale,phone_number,phone_number_verified,address,updated_at,cognito:mfa_enabled,cognito:username" >| $csv_file
aws cognito-idp list-users --user-pool-id $pool > $json_file
cat $json_file | \
    jq -r '.Users[] | [
        (.Attributes[] | select(.Name == "name") | .Value) // "NO",
        (.Attributes[] | select(.Name == "email") | .Value) // "noname",
        (.Attributes[] | select(.Name == "email_verified") | .Value) // "false"
    ] | join(" ")' | \
        while read line; do
            set -- $line
            name="$1"
            email="$2"
            verified_email="$3"
            echo "${name},,,,,,,,,${email},${verified_email^^},,,,,,FALSE,,,FALSE,${email}" >> $csv_file
        done

import -

#!/usr/bin/env bash

env="${1:-demo}"
pool=$(aws cognito-idp list-user-pools --max-results 20 | jq -r --arg env $env '.UserPools[] | select(.Name|test($env)) | .Id')
csv_file="/tmp/userpool-users.csv"

echo env $env
echo pool $pool
echo csv_file $csv_file

aws cognito-idp create-user-import-job \
    --job-name cognito-import-$RANDOM \
    --user-pool-id $pool  \
    --cloud-watch-logs-role-arn arn:aws:iam::******:role/cognito-import-job-role | \
    jq -r '.UserImportJob | [.JobId, .UserPoolId, .PreSignedUrl] | join(" ")' | \
        while read line; do
            set -- $line
            job="$1"
            pool="$2"
            url="$3"
            curl -s -T $csv_file -H "x-amz-server-side-encryption:aws:kms" "$url"
            aws cognito-idp start-user-import-job --user-pool-id $pool --job-id $job
        done

iam role can be seen here - https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-using-import-tool-cli-cloudwatch-iam-role.html

Aadil009 commented 1 year ago

Getting same error. In my case I don't have aws setup locally. So I installed AWS Cli and configure it locally using aws configure command. Then I gave access id, secret id, region and JSON as default output format and after that I ran script, It worked. Hope this might be issue with you as well.

samprit-utl commented 1 year ago

For those, who are getting issues like "Something else went wrong.", Just open up the Python Script "CognitoUserToCSV.py" in any code editor and place the following AWS Access Key and AWS Secret Key like below: image

After that, it should be working fine.

PS: You can find those AWS credentials in your IAM console of the same AWS account.

miladtsx commented 8 months ago

@hawkerfun I adjusted the code (#13) to show the exact error message instead of only showing a General error message: Something else went wrong.