Connect to Amazon S3 with boto3 with IAM roles

I am trying to upgrade from python boto to a newer boto3 module for managing files on Amazon S3.

I also need to use Amazon IAM roles, as with the old boto module. I'm not sure how the IAM role is configured on the server, but all I had to do was:

s3_conn = S3Connection()

and I get access to all the buckets that the server has access to.

This is similar to boto3:

s3 = boto3.resource('s3')
for bucket in s3.buckets.all():
     print(bucket.name)

I get an error message:

File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/boto3/resources/collection.py", line 83, in __iter__
  for page in self.pages():
File "/usr/local/lib/python2.7/dist-packages/boto3/resources/collection.py", line 161, in pages
  pages = [getattr(client, self._py_operation_name)(**params)]
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 310, in _api_call
  return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 407, in _make_api_call
  raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied

I am looking through the boto3 documentation, but I'm not sure what I need to do to configure IAM roles:

http://boto3.readthedocs.org/en/latest/

+4
source share
1 answer

s3:ListBucket . S3 .

+6

Source: https://habr.com/ru/post/1625139/


All Articles