【发布时间】:2016-09-16 23:33:02
【问题描述】:
我正在尝试运行一个简单的 AWS Cognito 实例。我创建了联合身份,并为经过身份验证和未经身份验证的用户分配了一个角色。我正在尝试连接到 Python 中的身份,但收到错误消息:
NoCredentialsError:无法找到凭据
我肯定使用了正确的 IdentityId,因为我直接从 AWS 控制台为您生成的代码示例中复制了它。我正在使用以下代码:
import boto3
identity = boto3.client('cognito-identity',
region_name='us-east-1')
response = identity.describe_identity(IdentityId='us-east-1:XXXX')
print (response['IdentityId'])
如果我尝试检索凭据,则会收到以下错误:
ClientError:调用 GetCredentialsForIdentity 操作时发生错误 (ResourceNotFoundException):未找到 Identity 'us-east-1:XXXXXX'。
使用此代码:
import boto3
identity = boto3.client('cognito-identity',
region_name='us-east-1')
response = identity.get_credentials_for_identity(IdentityId='us-east-1:XXXXX')
access_key = response['Credentials']['AccessKeyId']
secret_key = response['Credentials']['SecretKey']
print (access_key)
print (secret_key)
我还应该注意,如果我使用访问密钥和秘密创建身份客户端,我仍然会收到此处描述的第二个错误,但在这两种情况下。据我所知,我应该需要提供这些凭据,但我已经尝试过了。
【问题讨论】:
标签: python python-3.x amazon-web-services amazon-cognito boto3