[aioboto3] Access Denied when calling the ListObjects
akanshi-elastic opened this issue · 3 comments
akanshi-elastic commented
Requirements
- Async AWS SDK for Python version: 10.3.0
- Python version: 3.10.2
- Operating System: Linux
Description
I observed that when I create resource using default region which was mentioned in aws configure
and try to access(using same resource) a bucket(newly created bucket) in us-west-2
using aioboto3
it gives an error Access denied
for few days and then it starts working. Using boto3
it works fine.
Code Snipppet
import aioboto3
import asyncio
async def main():
session = aioboto3.Session()
async with session.resource('s3') as s3:
bucket = await s3.Bucket('s3-1-test-region')
async for s3_object in bucket.objects.all():
print(s3_object)
if __name__ == "__main__":
asyncio.run(main())
Traceback (most recent call last):
File "/root/sharepoint_auth.py", line 40, in <module>
asyncio.run(main())
File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 641, in run_until_complete
return future.result()
File "/root/sharepoint_auth.py", line 34, in main
async for obj_summary in bucket_obj.objects.page_size(10):
File "/usr/local/lib/python3.10/site-packages/aioboto3/resources/collection.py", line 25, in __anext__
async for page in cast(AsyncIterator[Any], self.pages()):
File "/usr/local/lib/python3.10/site-packages/aioboto3/resources/collection.py", line 73, in pages
async for page in pages:
File "/usr/local/lib/python3.10/site-packages/aiobotocore/paginate.py", line 30, in __anext__
response = await self._make_request(current_kwargs)
File "/usr/local/lib/python3.10/site-packages/aiobotocore/client.py", line 358, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the ListObjects operation: Access Denied
terricain commented
Can you reproduce the same using aiobotocore
?
akanshi-elastic commented
aiobotocore
getting same error while running the code with aioborocore as well:
import asyncio
from aiobotocore.session import get_session
async def go():
bucket = 'es-ent-2'
session = get_session()
async with session.create_client('s3') as client:
# get object from s3
response = await client.get_object(Bucket=bucket, Key="50kb-doc (4) (1).paper")
# this will ensure the connection is correctly re-used/closed
async with response['Body'] as stream:
print(await stream.read())
loop = asyncio.get_event_loop()
loop.run_until_complete(go())
terricain commented
Yup, so you'll need to raise an issue on the aiobotocore
repo then, as the calls by aioboto3 are passed through to it.