简体   繁体   English

AWS Cognito、AWS APIGateway 和 Python 凭证

[英]AWS Cognito, AWS APIGateway & credentials in Python

I want to perform something which I believe is pretty common and should therefore be simple : obtain credentials against Cognito authentication using Python to then be able to call an APIGateway method.我想执行一些我认为很常见的事情,因此应该很简单:使用 Python 获取针对 Cognito 身份验证的凭据,然后能够调用 APIGateway 方法。

I have created all ressources using the AWS SAM model.我已经使用 AWS SAM 模型创建了所有资源。 I can successfully see the Cognito user pool, its ID, the Cognito app client as well as a user.我可以成功地看到 Cognito 用户池、它的 ID、Cognito 应用程序客户端以及一个用户。 I am even able to authenticate using cURL.我什至可以使用 cURL 进行身份验证。

However, I can't replicate the same steps in Python :但是,我无法在 Python 中复制相同的步骤:

import boto3
import requests

region = 'eu-west-1'
cognito = boto3.client('cognito-identity', region)

accountId= 'xxxxxxxxxxxx' # 12 digits AWS account

poolId = 'something'
cognito .get_id(AccountId=accountId,IdentityPoolId=poolId)

and I have a problem with the poolId because I receive an exception :我的poolId有问题,因为我收到一个异常:

´´´Python Member must satisfy regular expression pattern: [\\w-]+:[0-9a-f-]+ ´´´ ´´´Python Member 必须满足正则表达式模式:[\\w-]+:[0-9a-f-]+ ´´´

but my poolId I see on AWS console is in the format eu-west-1:XXXXXXXXX whereas it should be in the format eu-west-1:xxx-xxx-xxx-xxxx-xxxx .但是我在 AWS 控制台上看到的poolId的格式为eu-west-1:XXXXXXXXX而它的格式应该是eu-west-1:xxx-xxx-xxx-xxxx-xxxx However, I can't find a value with that format anywhere in the console.但是,我在控制台的任何地方都找不到该格式的值。

Any help is appreciated.任何帮助表示赞赏。

You are confusing User Pool with Identity Pool.您将用户池与身份池混淆了。 To generate temporary IAM credentials, you need to create an Identity Pool and add your User Pool and app client under Authentication Providers.要生成临时 IAM 凭证,您需要创建一个身份池并在身份验证提供程序下添加您的用户池和应用程序客户端。 在此处输入图片说明

Also select choose role from token if you are using groups in your user pool.如果您在用户池中使用组,还可以选择从令牌中选择角色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM