【问题标题】:How to get temporary AWS credentials via Cognito Identity Pool如何通过 Cognito 身份池获取临时 AWS 凭证
【发布时间】:2021-01-05 23:39:58
【问题描述】:

我希望通过 Cognito 身份池获取临时 AWS 凭证,以通过 API Gateway 将数据发送到 Kinesis 流。 需要注意的一点是,我尝试在没有 AWS 开发工具包的情况下执行此操作,因为最终将使用它编写的语言没有兼容的开发工具包。我正在测试 Python 中的解决方案,并且似乎遗漏了一些东西,因为我不断收到 400 错误。关于我在这里做错了什么的任何想法?

import requests

url = 'https://cognito-identity.us-east-1.amazonaws.com' #cognito regional endpoint

headers = {
    'X-AMZ-TARGET': 'com.amazonaws.cognito.identity.model.AWSCognitoIdentityService.GetCredentialsForIdentity',
    'X-AMZ-DATE': '20151020T232759Z'
}

body = {
    'IdentityId': 'us-east-1:123456789' #identity id
}

response = requests.post(url = url, data = body, headers = headers)
print(response)

【问题讨论】:

    标签: python amazon-web-services aws-api-gateway amazon-cognito


    【解决方案1】:

    我能够通过添加内容类型标头、将正文中的单引号转换为双引号并将正文字典也用引号括起来来解决该问题。

    import requests
    
    url = 'https://cognito-identity.us-east-1.amazonaws.com' #cognito regional endpoint
    
    headers = {
        "CONTENT-TYPE": "application/x-amz-json-1.1",
        "X-AMZ-TARGET": "com.amazonaws.cognito.identity.model.AWSCognitoIdentityService.GetCredentialsForIdentity",
        "X-AMZ-DATE": "20151020T232759Z"
    }
    
    body = '''{
        "IdentityId": "123456789"
    }'''
    
    response = requests.post(url = url, data = body, headers = headers)
    print(response.text)
    

    【讨论】:

      猜你喜欢
      • 2020-04-12
      • 2019-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-16
      • 2020-12-17
      • 2017-12-03
      • 2021-04-10
      相关资源
      最近更新 更多