我是新来的AWS https://aws.amazon.com/ and boto 3 https://boto3.amazonaws.com/v1/documentation/api/latest/index.htmlPython SDK。我配置了Access Key ID
, Secret Access Key
和region name
通过AWS CLI https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration.
import boto3
client = boto3.client('cognito-idp')
response = client.admin_get_user(
UserPoolId='us-east-2_hJpikme9T',
Username='wasdkiller'
)
这是我的用户池 https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools.html细节,
我提供了正确的UserPoolId
,但是当我运行上面的代码示例时,我得到了以下每个函数的错误Cognito身份提供商 https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cognito-idp.html#id108,例如我使用的admin_get_user(**kwargs) https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cognito-idp.html#CognitoIdentityProvider.Client.admin_get_user.
ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the AdminGetUser operation: User pool us-east-2_hJpikme9T does not exist.
我们可以提供更多的论据boto3.client(*args, **kwargs) https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/boto3.html#boto3.client除了service_name
(默认参数)。如你看到的client() https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html#boto3.session.Session.client in 会话参考 https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html#module-boto3.session,我们可以提供aws_access_key_id
, aws_secret_access_key
, and region_name
不使用AWS CLI https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration.
如果您使用默认参数,例如您已经通过AWS CLI https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration没关系,你不需要提及aws_access_key_id
or aws_secret_access_key
打电话时boto3.client() https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/boto3.html#boto3.client。但我不知道出于某种原因你必须提及你的region_name
这是你已经通过的AWS CLI https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration打电话时boto3.client() https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/boto3.html#boto3.client.
client = boto3.client('cognito-idp', region_name='us-east-2')
这样我就解决了我上面的问题。但我还是不明白为什么我们要特别提到region_name
调用时的参数boto3.client() https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/boto3.html#boto3.client,如果您对此有任何了解,请更新此答案或在下面发表评论。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)