獲取在使用AWS JS SDK + DynamoDB這樣的錯誤:AWS JS SDK,IAM和DynamoDB問題
AccessDeniedException異常:用戶:阿爾恩:AWS:其:: [ACCNT ID]:假設角色/ dynamoIntroRole/web的身份無權執行:dynamodb:PutItem資源:阿爾恩:AWS:dynamodb:美西2:ACCNT ID]:表/ websiteTest
這是HTML/JS我用了:
<title>Insert title here</title>
</head>
<body>
<button id="login">Login</button>
<div id="fb-root"></div>
<script type="text/javascript">
var fbUserId;
var dynamodb = null;
var appId = '120636118298132'; //from facebook
var roleArn = 'arn:aws:iam::[my account id deleted]:role/dynamoIntroRole'; //from AWS IAM
window.fbAsyncInit = function() {
\t FB.init({appId : appId});
\t
\t document.getElementById('login').onclick = function(){
\t \t
\t FB.login(function (response)
\t {
\t \t if(response.authResponse)
\t \t {
\t \t \t AWS.config.credentials = new AWS.WebIdentityCredentials({ //WIF
\t \t \t \t RoleArn: roleArn,
\t \t \t \t ProviderId: 'graph.facebook.com',
\t \t \t \t WebIdentityToken: response.authResponse.accessToken
\t \t \t });
\t \t \t
\t \t \t var dynamodb = new AWS.DynamoDB({ region: 'us-west-2' });
\t \t \t var docClient = new AWS.DynamoDB.DocumentClient({ service: dynamodb });
\t \t \t console.log("You're now logged in.");
\t \t \t var params = {
\t \t \t \t \t TableName: 'websiteTest',
\t \t \t \t Item: {
\t \t \t \t itemID:'lkjljljlkjlkjlkjlkjlkj',
\t \t \t \t f2:'kjhkjhkjhkjhkjhkjhkjhkjhkjh'
\t \t \t \t }
\t \t \t \t };
\t \t \t \t docClient.put(params, function(err, data){
\t \t \t \t if (err) console.log(err);
\t \t \t \t else console.log(data);
\t \t \t \t });
\t \t }
\t \t else
\t \t \t {
\t \t \t console.log("Issue logging in");
\t \t \t }
\t \t
\t }); //end fb login
\t
\t \t };
\t };
\t // Load the FB JS SDK asynchronously
\t (function(d, s, id){
\t var js, fjs = d.getElementsByTagName(s)[0];
\t if (d.getElementById(id)) {return;}
\t js = d.createElement(s); js.id = id;
\t js.src = "//connect.facebook.net/en_US/all.js";
\t fjs.parentNode.insertBefore(js, fjs);
\t }(document, 'script', 'facebook-jssdk'));
</script>
</body>
這裏是我連接到角色的IAM策略中使用:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"dynamodb:DeleteItem",
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:Query",
"dynamodb:UpdateItem"
],
"Resource": [
"arn:aws:dynamodb:us-west-2:[my account deleted]:table/websiteTest"
],
"Condition": {
"ForAllValues:StringEquals": {
"dynamodb:LeadingKeys": [
"${graph.facebook.com:id}"
]
}
}
}
]
}
我缺少什麼?
你是正確的,肌。 Condition子句在刪除或修改時會更改將新數據插入表中的能力。 –