【问题标题】:How to import users(csv) to AWS cognito using presignedurl in python如何在 python 中使用 presignedurl 将用户(csv)导入 AWS cognito
【发布时间】:2020-05-10 01:25:20
【问题描述】:

我的任务是我知识有限。我的任务是获取一个充满用户数据的 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>
)

这部分有效,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

【问题讨论】:

  • 在较高级别使用请求库将 csv 文件发布到它提供给您的预签名 URL。
  • 你有想过这个吗?
  • @tanenbring 是的,我采取了不同的方法,结果成功了
  • 为什么要发布答案以结束问题并在未来帮助他人

标签: python amazon-web-services authentication boto3 amazon-cognito


【解决方案1】:

下面的代码 sn-p 帮助我将 csv 文件成功发布到预签名的 url

content_deposition =  'attachment;filename='+ 'filename.csv';
    headers_dict = {'x-amz-server-side-encryption': 'aws:kms',
         'Content-Disposition': content_deposition}
    presigned_url = response['UserImportJob']['PreSignedUrl']
    with open(CSV_FILE_NAME, 'rb') as f:
       file_upload_response = requests.put(
            presigned_url, data=f, headers=headers_dict)

【讨论】:

    猜你喜欢
    • 2017-09-22
    • 2021-07-30
    • 2021-08-04
    • 2021-03-18
    • 1970-01-01
    • 1970-01-01
    • 2017-12-27
    • 2020-09-01
    • 2014-03-17
    相关资源
    最近更新 更多