如何使用 python 中的 presignedurl 将用户(csv)导入到 AWS cognito

oli*_*ive 1 python authentication amazon-web-services amazon-cognito boto3

我的任务是完成一项我知识有限的任务。我的任务是获取包含用户数据的 csv 并使用 python 中的 boto3 将其导入到 aws cognito 中。到目前为止我有这个:

import boto3

client = boto3.client('cognito-idp')

response = client.create_user_import_job(
    JobName='TestImport',
    UserPoolId=<My unique string pool id>
    CloudWatchLogsRoleArn= <My unique stringrole arn id>
)
Run Code Online (Sandbox Code Playgroud)

本节工作并response输出一个字典,其中有一个名为 presignedurl 的键,我想用它来将 csv 上传到 cognitio 中。我只是不知道如何编写一个 python 函数,获取该响应字典并将 csv 上传到 cognito。任何帮助或指导表示赞赏。

谢谢你!

作为参考,我正在关注此文档: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cognito-idp.html#CognitoIdentityProvider.Client.list_user_import_jobs

小智 5

下面的代码片段帮助我将 csv 文件成功发布到预先签名的 url

headers = {'x-amz-server-side-encryption': 'aws:kms'}
presigned_url = response['UserImportJob']['PreSignedUrl']
with open(CSV_FILE_NAME, 'rb') as f:
    file_upload_response = requests.put(presigned_url, data=f, headers=headers)
Run Code Online (Sandbox Code Playgroud)