0

I'm trying to retrieve user list from my AWS Cognito User Pool.

When I enter this command to PowerShell, I can get users.json file as a result;

aws --region eu-central-XXXX cognito-idp list-users --user-pool-id eu-central-XXXX_AAAAAAA --output json > ~/users.json

I wrote a Python code to do same;

import boto3

REGION = 'eu-central-XXXX'
USER_POOL_ID = 'eu-central-XXXX_AAAAAAA'

client = boto3.client('cognito-idp', REGION)

user_records = client.list_users(UserPoolId=USER_POOL_ID)
print(user_records)

But I got botocore.exceptions.NoCredentialsError: Unable to locate credentials.

I see that I have ~/.aws/config and ~/.aws/credentials files and they have my information, I checked.

What is the problem? How can I solve my problem?

Wicaledon
  • 710
  • 1
  • 11
  • 26

1 Answers1

0

I found the solution;

import boto3

REGION = 'eu-central-XXXX'
USER_POOL_ID = 'eu-central-XXXX_AAAAAAA'

session = boto3.Session(profile_name = "YOUR_PROFILE_NAME_ON_CREDENTIALS_FILE"
client = session.client('cognito-idp', REGION)

user_records = client.list_users(UserPoolId=USER_POOL_ID)
print(user_records)
Wicaledon
  • 710
  • 1
  • 11
  • 26