AWS:在没有JS SDK的情况下为DynamoDB获取有限的IAM凭据

时间:2018-01-09 11:54:39

标签: amazon-web-services amazon-dynamodb amazon-cognito

我想要实现的目标: aws cognito dynamodb limited iam http call from browser to the database

我的案例在this article中有所描述,但我不想在我的网页上使用SDK - 我想保持我的应用程序简单快速,但事实证明 - 很难找到一个没有的例子使用SDK。我难以接受http调用,我需要从中获取DynamoDB的有限IAM凭据。在我对文档的调查中,我找到了方法GetCredentialsForIdentity,描述:

  

返回提供的身份ID的凭据。任何提供的登录   将针对支持的登录提供程序进行验证。如果令牌是   对于cognito-identity.amazonaws.com,它将被传递给AWS   安全令牌服务,具有令牌的适当角色。

但是在这个页面上没有提到该端点的url。我试过了 https://cognito-idp.us-east-1.amazonaws.com
https://cognito-identity.us-east-1.amazonaws.com
https://<mydomain>.auth.us-east-1.amazoncognito.com

我现在收到400错误,可能是因为端点网址不正确。我目前的代码:

fetch('https://cognito-identity.us-east-1.amazonaws.com', {
  'method': 'POST',
  'headers': {
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSCognitoIdentityService.GetCredentialsForIdentity',
   },
   'body': '{"IdentityId": "us-east-1:<GUID of the user>"}'
});

1)什么是http端点?
2)我正在朝着正确的方向挖掘吗?

1 个答案:

答案 0 :(得分:0)

正确的终点是
https://cognito-identity.us-east-1.amazonaws.com
according to this page

此外,我发现我需要提供sub来自id_token但不是GetId用户。