1
votes

I'm working to in a project and the goal is to pull report from amazon S3. Currently I'm trying to access to an S3 location to check my available bucket list.

Im working in python, I've set all my credentials in the prompt : aws configure.

In my python file when i'm try the code to list all my bucket :

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

I'm getting this error :

Traceback (most recent call last): File "C:\Users\bakpovo\testAmazon.py", line 3, in for bucket in s3.buckets.all(): File "C:\Users\bakpovo\AppData\Local\Programs\Python\Python38\lib\site-packages\boto3\resources\collection.py", line 83, in iter for page in self.pages(): File "C:\Users\bakpovo\AppData\Local\Programs\Python\Python38\lib\site-packages\boto3\resources\collection.py", line 161, in pages pages = [getattr(client, self._py_operation_name)(**params)] File "C:\Users\bakpovo\AppData\Local\Programs\Python\Python38\lib\site-packages\botocore\client.py", line 276, in _api_call return self._make_api_call(operation_name, kwargs) File "C:\Users\bakpovo\AppData\Local\Programs\Python\Python38\lib\site-packages\botocore\client.py", line 586, in _make_api_call raise error_class(parsed_response, operation_name) botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied

Does someone have any idea of what happened? Are my creadentials not good?

Thanks

1
1. Are you able to read/list the buckets with the aws s3 terminal/shell command? 2. After running aws configure do you have a valid shared credentials file ~/.aws/credentials? 3. Ref boto3.amazonaws.com/v1/documentation/api/latest/guide/… do you have anything that would prevent boto3 from using the shared credentials file (e.g. environment variables set)?Tom Dalton
did you create your credentials as the default profile? If you have multiple s3 accounts/ profiles it can be useful to setup named profiles and then create a session: session = boto3.Session(profile_name=<NAME HERE>) s3 = session.resource("s3")Alex
Hello @Tom, Thanks for replying. I have already use the 'aws s3 ls s3' in my terminal for the listing and I have the same error. Yes I've my credentials file valid.I don't think I've some environments variables. I just have an S3 location and the secret and access key idthenotoriousb
Hello @Alex, thanks for your answer... I dont create my credentials as default, i've just configure with the acces key id and the secret access key. My s3 location look like this : s3://aps-external-xxxx/aps-downloadxxx-xxx-43f7ee306fd2/thenotoriousb
If aws s3 ls s3 doesn't work with the same error then your credentials are not set up correctly.Tom Dalton

1 Answers

0
votes

Thanks you all for your answer. I solve my problem. I have just add to my shell syntax my s3 location like this :

aws s3 ls s3://aps-external-xxxx/aps-downloadxxx-xxx-e306fd2/

And it's work.