Skip to content

Commit

Permalink
reusable fix
Browse files Browse the repository at this point in the history
  • Loading branch information
avishniakov committed Oct 16, 2024
1 parent b14e6dd commit eea0acf
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/zenml/integrations/s3/artifact_stores/s3_artifact_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,7 @@ def __init__(
super().__init__(*args, **kwargs)

# determine bucket versioning status
key, secret, token, region = self.get_credentials()
s3 = boto3.resource(
"s3",
aws_access_key_id=key,
aws_secret_access_key=secret,
aws_session_token=token,
region_name=region,
)
bucket = s3.Bucket(self.config.bucket)
versioning = bucket.Versioning()
versioning = self._boto3_bucket.Versioning()
if versioning.status == "Enabled":
self.is_versioned = True
logger.warning(
Expand Down Expand Up @@ -474,10 +465,27 @@ def _remove_previous_file_versions(self, path: PathType) -> None:
if isinstance(path, bytes):
path = path.decode()
_, prefix = split_s3_path(path)
s3 = boto3.resource("s3")
bucket = s3.Bucket(self.config.bucket)
for version in bucket.object_versions.filter(Prefix=prefix):
for version in self._boto3_bucket.object_versions.filter(
Prefix=prefix
):
if not version.is_latest:
version.delete()

return

@property
def _boto3_bucket(self) -> boto3.resources.factory.s3.Bucket:
"""Get the boto3 bucket object.
Returns:
The boto3 bucket object.
"""
key, secret, token, region = self.get_credentials()
s3 = boto3.resource(
"s3",
aws_access_key_id=key,
aws_secret_access_key=secret,
aws_session_token=token,
region_name=region,
)
return s3.Bucket(self.config.bucket)

0 comments on commit eea0acf

Please sign in to comment.