3

ドキュメントから把握しようとしましたが、s3 バケットにアクセスできるフェデレーション ユーザーを作成できません

まずは輸入物

>>> from boto.s3.connection import S3Connection
>>> from boto.sts import STSConnection

次に、s3 でバケットを作成します。

>>> s3c = ('access key', 'secret key')  
>>> s3c.create_bucket('ranjith_new_bucket')

次に、フェデレーション ユーザーを作成します。これは、私が正しく理解している場合、一時的な資格情報を作成する方法です。

>>> sts = STSConnection('access key', 'secret key')  
>>> user = sts.get_federation_token('guest_user_1')

しかし、アクセス可能なすべてのバケットのリストを取得しようとすると、エラーが発生します。

>>> s3c2 = S3Connection(user.credentials.access_key, user.credentials.secret_key)
>>> s3c2.get_all_buckets()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ranjith/work/venv/local/lib/python2.7/site-packages/boto-2.16.0-py2.7.egg/boto/s3/connection.py", line 387, in get_all_buckets
    response.status, response.reason, body)
boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>InvalidAccessKeyId</Code><Message>The AWS Access Key Id you provided does not exist in our records.</Message><RequestId>154CDA2184E00650</RequestId><HostId>xxx</HostId><AWSAccessKeyId>xxx</AWSAccessKeyId></Error>

ドキュメントには、ポリシー文字列を提供する必要があると書かれていますが、ドキュメントを理解するのは非常に困難です。どこかでポリシーを定義し、フェデレーション ユーザーの作成中にそれを使用する必要があることはわかっていますが、それをどこでどのように行うかはわかりません。

私はこれを試しました:

permission = {
  "Version": "2012-10-17",
  "Statement": [
    {
       "Effect": "Allow",
       "Action": ["sts:GetFederationToken"],
       "Resource": "*"
     },
    {
       "Effect": "Allow",
       "Action": ["s3:*"],
       "Resource": "arn:aws:s3:::mybucket/ranjith_new_bucket/*"
     }
   ]
 }

sts.get_federation_token('some_other_user', json.dumps(permission))

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ranjith/work/venv/local/lib/python2.7/site-packages/boto-2.16.0-py2.7.egg/boto/sts/connection.py", line 235, in get_federation_token
    FederationToken, verb='POST')
  File "/home/ranjith/work/venv/local/lib/python2.7/site-packages/boto-2.16.0-py2.7.egg/boto/connection.py", line 1138, in get_object
    raise self.ResponseError(response.status, response.reason, body)
boto.exception.BotoServerError: BotoServerError: 400 Bad Request
<ErrorResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
  <Error>
    <Type>Sender</Type>
    <Code>MalformedInput</Code>
  </Error>
  <RequestId>75734932-4ac1-11e3-a17b-e9e245983c07</RequestId>
</ErrorResponse>

私がしたのはポリシーのjsonダンプを入れることだけだったので、これは本当にばかげています。問題に関するオンライン リソースを見つけることさえできません。

上で作成したものへのアクセス権を持つフェデレーション ユーザーを作成することになるように、誰かが私を導くことができれば素晴らしいことですranjith_new_bucket。コード スニペットを歓迎します。

4

1 に答える 1