Boto3 and OVH: GetObject error the specified bucket is not valid

186 Views Asked by At

I'm currently trying to implement a get Object request from Object Storage – S3 API OVH. I have the same implementation for a project using python and wanted to integrate it here, but do to a lack of knowledge of the language I believe I may be missing something. I'm getting this error:

The specified bucket is not valid.

import boto3

client = boto3.client(
    's3',
    aws_access_key_id=ACCESS_KEY,
    aws_secret_access_key=SECRET_KEY,
    aws_endpoint_url=ENDPOINT_URL,
    region_name=REGION_NAME
)

s3_response_object = s3_client.get_object(Bucket=BUCK_NAME_IS_STRING, Key='KEY_STRING')

print(s3_response_object)

Things I've tried:

I confirmed that the bucket name is accurate and verified the relevant permissions. These environment variables have been successfully utilized in another project using JavaScript without issues.

Notably, altering variables such as aws_access_key_id and aws_secret_access_key did not affect the error message, suggesting that the issue might be related to a format error.

ovh relevant documentation:

Object Storage - Endpoints and Object Storage geoavailability

https://help.ovhcloud.com/csm/en-ie-public-cloud-storage-s3-location?id=kb_article_view&sysparm_article=KB0047393

Object Storage Swift - S3/Swift REST API compatibility

https://help.ovhcloud.com/csm/en-ie-public-cloud-storage-pcs-s3-swift-rest-api-compatibility?id=kb_article_view&sysparm_article=KB0047197

1

There are 1 best solutions below

0
On

Additional information

Thank you, John, for sharing this post. The link you shared provided the final piece of the puzzle. Here is the bug posted by mh4ckt3mh4ckt1c4s at

https://github.com/boto/boto3/issues/3258

I wanted to add some information that is relevant to the issue mentioned on GitHub, which is related to the retrieval of credentials from the OVH control panel. OVH provides a URL in this format: https://storage.region.cloud.ovh.net In my case, I was using the wrong URL, as "storage" is the legacy name that is still used for backward compatibility. The correct URL is: https://s3.region.cloud.ovh.net**

The problem with the CLI not working was also due to the same reason. However, it was an easy fix - I just had to set it up at ~/.aws/config

Solution

import boto3

client = boto3.client(
    's3',
    aws_access_key_id=ACCESS_KEY,
    aws_secret_access_key=SECRET_KEY,
    aws_endpoint_url= https://s3.<region>.cloud.ovh.net,
    region_name=REGION_NAME
)