-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
The existing python code for bucket forking incorrectly mutates s3 clients such that the first call always works but any successive call fails. Edit the python examples to look like this instead:
import boto3
from botocore.client import Config
def create_bucket_with_snapshotting_enabled(bucket_name):
tigris = boto3.client(
"s3",
endpoint_url="https://t3.storage.dev",
config=Config(s3={'addressing_style': 'virtual'}),
)
tigris.meta.events.register(
"before-sign.s3.CreateBucket",
lambda request, **kwargs: request.headers.add_header("X-Tigris-Enable-Snapshot", "true")
)
tigris.create_bucket(Bucket=bucket_name)
def create_bucket_snapshot(bucket_name, desc):
tigris = boto3.client(
"s3",
endpoint_url="https://t3.storage.dev",
config=Config(s3={'addressing_style': 'virtual'}),
)
tigris.meta.events.register(
"before-sign.s3.CreateBucket",
lambda request, **kwargs: request.headers.add_header(
"X-Tigris-Snapshot", f"true; desc={desc}"
)
)
tigris.create_bucket(Bucket=bucket_name)
def list_snapshots_for_bucket(bucket_name):
tigris = boto3.client(
"s3",
endpoint_url="https://t3.storage.dev",
config=Config(s3={'addressing_style': 'virtual'}),
)
tigris.meta.events.register(
"before-sign.s3.ListBuckets",
lambda request, **kwargs: request.headers.add_header("X-Tigris-Snapshot", bucket_name)
)
return tigris.list_buckets()
def create_bucket_fork(bucket_name, from_bucket):
tigris = boto3.client(
"s3",
endpoint_url="https://t3.storage.dev",
config=Config(s3={'addressing_style': 'virtual'}),
)
tigris.meta.events.register(
"before-sign.s3.CreateBucket",
lambda request, **kwargs: (
request.headers.add_header("X-Tigris-Fork-Source-Bucket", from_bucket),
)
)
tigris.create_bucket(Bucket=bucket_name)
For every python call in the bucket forking code, replace them with functions like that. Mention in each section that you must set the right aws profile or environment variables for each call.
Copilot