Skip to content

Commit

Permalink
Ignore the legacy S3 global endpoint URL
Browse files Browse the repository at this point in the history
AWS deprecated the https://s3.amazonaws.com endpoint URL we recommend
and botocore started enforcing the use of regional endpoint URLs
instead since version 1.28.0.

This updates the S3 model to ignore the legacy URL and let botocore to
calculate it from the bucket region.
  • Loading branch information
replaceafill committed Mar 12, 2024
1 parent 2da91e1 commit cbf7f64
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion storage_service/locations/models/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pprint
import re
from functools import wraps
from urllib.parse import urlparse

import boto3
import botocore
Expand Down Expand Up @@ -75,10 +76,11 @@ def resource(self):
)
boto_args = {
"service_name": "s3",
"endpoint_url": self.endpoint_url,
"region_name": self.region,
"config": config,
}
if not self._is_global_endpoint(self.endpoint_url):
boto_args["endpoint_url"] = self.endpoint_url
if self.access_key_id and self.secret_access_key:
boto_args.update(
aws_access_key_id=self.access_key_id,
Expand All @@ -87,6 +89,9 @@ def resource(self):
self._resource = boto3.resource(**boto_args)
return self._resource

def _is_global_endpoint(self, url):
return urlparse(url).netloc == "s3.amazonaws.com"

@boto_exception
def _ensure_bucket_exists(self):
"""Ensure that the bucket exists by asking it something about itself.
Expand Down

0 comments on commit cbf7f64

Please sign in to comment.