Python - Export AWS Cognito User Pool - NoCredentialsError: Unable to locate credentials
Python - Export AWS Cognito User Pool - NoCredentialsError: Unable to locate credentials
我正在尝试从我的 AWS Cognito 用户池中检索用户列表。
当我在 PowerShell 中输入此命令时,我可以得到 users.json
个文件;
aws --region eu-central-XXXX cognito-idp list-users --user-pool-id eu-central-XXXX_AAAAAAA --output json > ~/users.json
我写了一个 Python 代码来做同样的事情;
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)
但是我得到了botocore.exceptions.NoCredentialsError: Unable to locate credentials
。
我看到我有 ~/.aws/config
和 ~/.aws/credentials
文件,他们有我的信息,我检查过。
问题是什么?我该如何解决我的问题?
我找到了解决方案;
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)
我正在尝试从我的 AWS Cognito 用户池中检索用户列表。
当我在 PowerShell 中输入此命令时,我可以得到 users.json
个文件;
aws --region eu-central-XXXX cognito-idp list-users --user-pool-id eu-central-XXXX_AAAAAAA --output json > ~/users.json
我写了一个 Python 代码来做同样的事情;
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)
但是我得到了botocore.exceptions.NoCredentialsError: Unable to locate credentials
。
我看到我有 ~/.aws/config
和 ~/.aws/credentials
文件,他们有我的信息,我检查过。
问题是什么?我该如何解决我的问题?
我找到了解决方案;
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)