我怎么能叫AssumeRoleWithWebIdentity访问亚马逊DynamoDB? [英] How can I call AssumeRoleWithWebIdentity to access Amazon DynamoDB?

查看:291
本文介绍了我怎么能叫AssumeRoleWithWebIdentity访问亚马逊DynamoDB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情景:
我在亚马逊创建一个应用程序,并使用登录亚马逊,它返回一个access_token。然后我运行:

Scenario:
I create an app on Amazon, and use Login with Amazon, which returns an "access_token". Then I run:

  AWS.config.credentials = new AWS.WebIdentityCredentials({

          RoleArn: 'arn:aws:iam::416942672???:role/???_amazon_role',
          ProviderId: 'www.amazon.com',
          WebIdentityToken:"?????????"
        });

  AWS.config.region = 'us-west-2';

  dynamodb =  new  AWS.DynamoDB()   dynamodb.listTables({}, function a(error,data){

    alert( "error: " +  JSON.stringify(error) );
    alert( JSON.stringify(data) );
    });

在我以后运行 ListTable 函数将返回:

When I later run the ListTable function it will return:

error: {"message":"Missing credentials in config","code":"SigningError","name":"SigningError","statusCode":403,"retryable":false}

我发现好像是我必须调用 AssumeRoleWithWebIdentity 。但是,我怎么能叫它 AWS SDK为JavaScript ?或者有没有其他的过程中,我错过了吗?

I found it seems that I have to call AssumeRoleWithWebIdentity. But how can I call it in AWS SDK for JavaScript? Or is there any other process I missed?

推荐答案

的<一个过程href="http://docs.aws.amazon.com/STS/latest/UsingSTS/CreatingWIF.html#CreatingWIF-getting-temp-creds"相对=nofollow>获取临时凭据中确实需要调用的 AssumeRoleWithWebIdentity - 这种低级别的API调用是隐含在较高的水平 AWS SDK为JavaScript 凭据提供呼叫新AWS.WebIdentityCredentials(不过,如见) 类:AWS.WebIdentityCredentials 的:

The process of Getting Temporary Credentials indeed requires a call to AssumeRoleWithWebIdentity - this low level API call is implied in the higher level AWS SDK for JavaScript credentials provider call new AWS.WebIdentityCredentials() though, see e.g. Class: AWS.WebIdentityCredentials:

再presents从STS的Web身份联合检索凭据   支持。

Represents credentials retrieved from STS Web Identity Federation support.

在默认情况下使用此提供程序获得证书   <一href="http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/STS.html#assumeRoleWithWebIdentity-property"相对=nofollow> AWS.STS.assumeRoleWithWebIdentity()的服务操作。此操作   需要包含IAM信任策略的ARN为一个RoleArn   申请该证书将得到。此外,该   WebIdentityToken必须设置由身份提供的令牌   供应商。请参阅<一href="http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/WebIdentityCredentials.html#constructor-property"相对=nofollow>构造函数()一个例子创建一个凭证   对象适当RoleArn和WebIdentityToken值。

By default this provider gets credentials using the AWS.STS.assumeRoleWithWebIdentity() service operation. This operation requires a RoleArn containing the ARN of the IAM trust policy for the application for which credentials will be given. In addition, the WebIdentityToken must be set to the token provided by the identity provider. See constructor() for an example on creating a credentials object with proper RoleArn and WebIdentityToken values.

由于错误信息的缺少配置凭据的,你显然传递了不正确的 WebIdentityToken ,这是不是一个惊喜给你只是规定了一些 ????????? 占位符;) - 因为你已经的使用登录亚马逊,它返回一个access_token 的,你会只需要传递ACCESS_TOKEN,而不是那些内容 ????????? 占位符值 WebIdentityToken 和应该准备就绪。

Given the error message "Missing credentials in config", you are obviously passing an incorrect WebIdentityToken, which isn't a surprise given you just specified some ????????? placeholders ;) - since you already use Login with Amazon, which returns an access_token, you'll just need to pass the content of that ACCESS_TOKEN instead of those ????????? placeholders as value for WebIdentityToken and should be all set.

  • For other readers: Section 6. Putting it all together of Configuring Web Identity Federation in the Browser provides an example for retrieving the access token via Facebook Login. As noted there, Other identity providers will have a similar setup step that involves loading the respective SDK, logging in, and receiving an access token - in particular, how to handle Login with Amazon is documented in detail within Getting Started for Web.

这篇关于我怎么能叫AssumeRoleWithWebIdentity访问亚马逊DynamoDB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆