我正在开发一个 python 应用程序,其目的是将数据上传到 S3。由于它必须独立安装在不同的设备上,我不希望在每个平台上都存储 aws 凭证,但我想创建一个基于Amazon Cognito的身份验证方法。
需要一个基于用户名和密码的登录方式,所以用户必须经过身份验证才能被授权上传文件。我创建了一个用户池和身份池,这是我想要遵循的模式:
这是我为验证用户而编写的代码:
import os
import boto3
username = "user1997"
password = "abcd1234!!"
client = boto3.client("cognito-idp", region_name="ap-south-1")
response = client.initiate_auth(
ClientId=os.getenv("COGNITO_USER_CLIENT_ID"),
AuthFlow="USER_PASSWORD_AUTH",
AuthParameters={"USERNAME": username, "PASSWORD": password},
)
access_token = response["AuthenticationResult"]["AccessToken"]
但我不知道如何使用access_token
从Identity Pool获取临时凭据。