2017-08-05 195 views

回答

1

您需要設置STS並擔任角色以獲取臨時憑證以訪問AWS服務。

/* */ 

var params = { 
    DurationSeconds: 3600, 
    RoleArn: "arn:aws:iam::123456789012:role/demo", 
    RoleSessionName: "Bob" 
}; 
sts.assumeRole(params, function(err, data) { 
    if (err) console.log(err, err.stack); // an error occurred 
    else  console.log(data);   // successful response 
    /* 
    data = { 
    AssumedRoleUser: { 
    Arn: "arn:aws:sts::123456789012:assumed-role/demo/Bob", 
    AssumedRoleId: "ARO123EXAMPLE123:Bob" 
    }, 
    Credentials: { 
    AccessKeyId: "AKIAIOSFODNN7EXAMPLE", 
    Expiration: <Date Representation>, 
    SecretAccessKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY", 
    SessionToken: "AQoDYXdzEPT//////////wEXAMPLEtc764bNrC9SAPBSM22wDOk4x4HIZ8j4FZTwdQWLWsKWHGBuFqwAeMicRXmxfpSPfIeoIYRqTflfKD8YUuwthAx7mSEI/qkPpKPi/kMcGdQrmGdeehM4IC1NtBmUpp2wUE8phUZampKsburEDy0KPkyQDYwT7WZ0wq5VSXDvp75YU9HFvlRd8Tx6q6fE8YQcHNVXAkiY9q6d+xo0rKwT38xVqr7ZD0u0iPPkUL64lIZbqBAz+scqKmlzm8FDrypNC9Yjc8fPOLn9FX9KSYvKTr4rvx3iSIlTJabIQwj2ICCR/oLxBA==" 
    }, 
    PackedPolicySize: 6 
    } 
    */ 
}); 

http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/STS.html#assumeRole-property

+0

感謝strongjz,我肯定會嘗試。也有可能做同樣的事情使用認知身份池ID來訪問我是角色s3圖像 –

+0

我還沒有與Cognito合作過,但閱讀它,似乎很http://docs.aws.amazon.com/cognito /latest/developerguide/iam-roles.html – strongjz