2016-02-29 96 views
0

我想给阅读(下载)权利给单个用户。 我感到困惑,我应该用什么:AWS S3政策混淆

我应该使用

  • 遗愿策略编辑器从S3接口
  • 用户的在线策略,并指定读取权限(从IAM接口)
  • 激活“任何经过身份验证的AWS用户”有权读取(从s3界面),然后使用内联权限获取更多粒度?

我使用的直列政策,它不会工作:

{ 
    "Version": "2012-10-17", 
    "Statement": [ 
     { 
      "Sid": "AllowUserToReadObject", 
      "Action": [ 
       "s3:GetObject", 
       "s3:GetObjectVersion", 
       "s3:GetObjectTorrent" 
      ], 
      "Effect": "Allow", 
      "Resource": [ 
       "arn:aws:s3:::staging/*", 
       "arn:aws:s3:::prod/*" 
      ] 
     } 
    ] 
} 

当我使用的Boto:

#!/usr/bin/env python 
# -*- coding: utf-8 -*- 
from boto.s3.connection import S3Connection 
from boto.s3.key import Key 
import sys, os 

AWS_KEY = '' 
AWS_SECRET = '' 



from boto.s3.connection import S3Connection 

conn = S3Connection(AWS_KEY, AWS_SECRET) 

bucket = conn.get_bucket('staging') 
for key in bucket.list(): 
    print key.name.encode('utf-8') 

我得到了以下错误:

Traceback (most recent call last): 
    File "listing_bucket_files.py", line 20, in <module> 
    bucket = conn.get_bucket('staging') 
    File "/usr/local/lib/python2.7/dist-packages/boto/s3/connection.py", line 503, in get_bucket 
    return self.head_bucket(bucket_name, headers=headers) 
    File "/usr/local/lib/python2.7/dist-packages/boto/s3/connection.py", line 536, in head_bucket 
    raise err 
boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden 

回答

0

您没有分配"s3:ListBucket"权限,该帐户已停止在访问存储桶stagingprod,则没有权限访问这些存储桶中的文件/文件夹。

请记住,您必须如下分隔代码,并且不要在存储桶名称后添加/*

"Statement": [ 
     { 
      "Effect": "Allow", 
      "Action": [ 
       "s3:ListBucket" 
      ], 
      "Resource": [ 
       "arn:aws:s3:::staging", 
       "arn:aws:s3:::prod", 
      ] 
     }, 
+0

谢谢,我保留了我的代码,并添加了's3:ListBucket'。 – 4m1nh4j1