I am attempting to use S3 Ninja with boto3 in Python, but despite the docker container running, I am unable to configure the S3 client to use S3 Ninja.
When attempting to GET an object using boto3.session.Session().client().get_object(), my attempts result in the following error.
s3 = S3()
content = s3.get('mybucket', 'myobject')
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "http://localhost:9444/mybucket/myobject.json"
Using curl http://localhost:9444/mybucket/myfile.json returns the file as expected so it seems as though S3 Ninja is working. However, the S3 client cannot find it for some reason.
I have tried both of the following values for the endpoint URL.
- http://localhost:9444
- http://localhost:9444/s3
class S3:
client: boto3.client
def __init__(self) -> None:
local = os.environ.get('LOCAL')
if local == 'true':
self.client = boto3.session.Session().client(
service_name='s3',
aws_access_key_id='my_access_key',
aws_secret_access_key='my_secret_key',
endpoint_url='http://localhost:9444',
config=botocore.client.Config(
s3={
'addressing_style': 'path'
}
)
)
else:
self.client = boto3.client('s3')
def get(self, bucket_name: str, key: str) -> str:
response = self.client.get_object(
Bucket=bucket_name,
Key=key)
return response['Body'].read().decode('utf-8')
What's the issue?