2016-12-21 64 views
0

我正在學習AWS CLI,但我試圖從本地文件夾複製到S3中的存儲桶...因此,當我鍵入命令輸出返回下一個錯誤:存儲桶策略編輯器:策略無法解析爲有效的JSON字符串

upload failed: ./lalala.txt to s3://buecket_name/ An error occurred (AccessDenied) when calling the PutObject operation: Access Denied

所以我搜一下這個和互聯網告訴我,問題是在桶策略編輯器,所以我嘗試編輯政策,但是當我點擊保存錯誤是:

Bucket Policy Editor:Policy could not be parsed as a valid JSON string

我的策略腳本:

{ 
    "Version": "2012-10-17", 
    "Statement": [ 
    { 
     "Effect": "Allow", 
     "Action": "s3:ListAllMyBuckets" 
     "Resource": "arn:aws:s3:::bucket-name*" 
    }, 
    { 
     "Effect": "Allow", 
     "Action": [ 
     "s3:ListBucket", 
     "s3:GetBucketLocation", 
     "s3:PutObject" 
     ], 
     "Resource": "arn:aws:s3:::bucket-name" 
    }, 
    { 
     "Effect": "Allow", 
     "Action": [ 
     "s3:PutObject", 
     "s3:GetObject", 
     "s3:DeleteObject" 
     ], 
     "Resource": "arn:aws:s3:::bucket-name/*" 
    } 
    ] 
} 

_____UPDATE_____:

所以,球員,我試圖改變腳本添加 「校長」,因爲下面的人建議,但錯誤繼續:

Policy could not be parsed as a valid JSON string

當前腳本:

{ 
    "Version": "2012-10-17", 
    "Statement": [ 
    { 
     "Effect": "Allow", 
     "Action": "s3:ListAllMyBuckets", 
     "Resource": "arn:aws:s3:Sao Paulo:X1X8XX6YYY16X:name-bucket*" 
    }, 
    "Principal": { 
     "AWS": [ 
     "arn:aws:iam::AWS-account-ID:root" 
     ] 
    } 
    { 
     "Effect": "Allow", 
     "Action": [ 
     "s3:ListBucket", 
     "s3:GetBucketLocation", 
     "s3:PutObject" 
     ], 
     "Resource": "arn:aws:s3:::bucket-name" 
    }, 
    { 
     "Effect": "Allow", 
     "Action": [ 
     "s3:PutObject", 
     "s3:GetObject", 
     "s3:DeleteObject" 
     ], 
     "Resource": "arn:aws:s3:::bucket-name/*" 
    } 
    ] 
} 

所以大家好,我做錯了什麼?

感謝先進!

回答

1

你缺少第1作用部後一個逗號:

"Action": "s3:ListAllMyBuckets", 

驗證JSONs可以通過服務,如jslint來完成。

+0

我把逗號,現在的錯誤是:'缺少必填字段主體 - 未定義' –

+1

@DouglasDiasdaSilva - 您需要指定一個描述誰可以訪問您的S3存儲桶的「Principal」字段。詳情請見[S3 Documentation](http://docs.aws.amazon.com/AmazonS3/latest/dev/s3-bucket-user-policy-specifying-principal-intro.html)。 – birryree

0

進行讀/寫於特定的桶政策是如下

{ 
"Version": "2012-10-17", 
"Statement": [   
    { 
     "Sid": "S3Actions", 
     "Resource": [ 
      "arn:aws:s3:::bucket-name/*", 
      "arn:aws:s3:::bucket-name"    
     ], 
     "Action": [ 
      "s3:DeleteObject", 
      "s3:PutBucketAcl", 
      "s3:PutObject", 
      "s3:PutObjectAcl", 
      "s3:Get*", 
      "s3:List*" 
     ], 
     "Effect": "Allow" 
    } 
] 
} 

您也可以使用Policy Simulator在這裏您可以選擇的政策和嘗試,以確保適當的動作被選擇來執行你的API通話沒有任何問題。

+0

我嘗試這樣做,但錯誤將繼續... –

+0

@DouglasDiasdaSilva:有一個額外的逗號可能導致策略失敗。我已經更新了它,所以請再試一次,它應該工作。 – Rajesh

+0

這是工作,謝謝兄弟! –