diff --git a/arena/notebooks/arena/object_storage_helpers.py b/arena/notebooks/arena/object_storage_helpers.py index f57bafa..6e3594c 100644 --- a/arena/notebooks/arena/object_storage_helpers.py +++ b/arena/notebooks/arena/object_storage_helpers.py @@ -279,6 +279,56 @@ def get_s3_client(use_lota: bool = False): ) +def create_bucket(bucket_name: str, use_lota: bool = False) -> bool: + """ + Create an S3 bucket (S3-compatible; e.g. CoreWeave CAIOS/LOTA). + + Args: + bucket_name: Name for the new bucket (must be globally unique). + use_lota: If True, use LOTA endpoint. + + Returns: + True if the bucket was created or already exists, False on error. + """ + if not bucket_name or not bucket_name.strip(): + print("Error: bucket name is required") + return False + bucket_name = bucket_name.strip() + config = get_config() + region = config.get("AWS_DEFAULT_REGION", "us-east-1") + s3 = get_s3_client(use_lota=use_lota) + try: + s3.create_bucket( + Bucket=bucket_name, + CreateBucketConfiguration={"LocationConstraint": region}, + ) + print(f"Created bucket: {bucket_name}") + return True + except s3.exceptions.ClientError as e: + code = e.response.get("Error", {}).get("Code", "") + if code in ("BucketAlreadyExists", "BucketAlreadyOwnedByYou"): + print(f"Bucket already exists: {bucket_name}") + return True + # Some S3-compatible endpoints don't support LocationConstraint; try without + if code in ("InvalidLocationConstraint", "IllegalLocationConstraintException"): + try: + s3.create_bucket(Bucket=bucket_name) + print(f"Created bucket: {bucket_name}") + return True + except s3.exceptions.ClientError as e2: + code2 = e2.response.get("Error", {}).get("Code", "") + if code2 in ("BucketAlreadyExists", "BucketAlreadyOwnedByYou"): + print(f"Bucket already exists: {bucket_name}") + return True + print(f"Error creating bucket: {e2}") + return False + print(f"Error creating bucket: {e}") + return False + except Exception as e: + print(f"Error creating bucket: {e}") + return False + + def list_buckets(use_lota: bool = False) -> List[str]: """ List all available S3 buckets. diff --git a/arena/notebooks/arena_caios_lota_setup_walkthrough_benchmarks.py b/arena/notebooks/arena_caios_lota_setup_walkthrough_benchmarks.py index b589249..44610c9 100644 --- a/arena/notebooks/arena_caios_lota_setup_walkthrough_benchmarks.py +++ b/arena/notebooks/arena_caios_lota_setup_walkthrough_benchmarks.py @@ -21,18 +21,21 @@ def _(): import marimo as mo from arena.object_storage_helpers import ( apply_policy, + create_bucket, list_buckets, list_policies, ) from arena.remote_execution_helpers import shell - return apply_policy, json, list_buckets, list_policies, mo, os, shell, time + import secrets + + return apply_policy, create_bucket, json, list_buckets, list_policies, mo, os, secrets, shell, time @app.cell(hide_code=True) def _(mo): mo.md(r""" - # CoreWeave AI Labs: Object Storage & LOTA + # CoreWeave ARENA: Object Storage & LOTA /// admonition | About This Notebook type: info @@ -73,6 +76,15 @@ def _(mo): """) return +@app.cell +def _(shell): + os.environ['AWS_ACCESS_KEY_ID'] = "your-key-here" + os.environ['AWS_SECRET_ACCESS_KEY'] = "your-secret-key-here" + os.environ['AWS_DEFAULT_REGION'] = "cw-region" # For example US-EAST-04 + os.environ['S3_ENDPOINT_URL'] = "http://cwlota.com" + os.environ['API_ACCESS_TOKEN'] = "your-access-token-here" + return + @app.cell(hide_code=True) def _(mo): @@ -178,12 +190,51 @@ def _(mo): /// admonition | S3 Buckets type: info - List and manage your S3 buckets. Buckets are the top-level containers for your objects. + Create a bucket below, then list and manage your S3 buckets. Buckets are the top-level containers for your objects. /// """) return +@app.cell(hide_code=True) +def _(mo): + mo.md(r""" + ### Create a bucket + + Bucket names must be globally unique. A random suffix is pre-filled; you can change it. + """) + return + + +@app.cell +def _(secrets): + default_bucket_name = "my-test-bucket-" + secrets.token_hex(4) + return (default_bucket_name,) + + +@app.cell +def _(default_bucket_name, mo): + bucket_name = mo.ui.text(value=default_bucket_name, label="Bucket name") + create_bucket_btn = mo.ui.run_button(label="Create bucket") + mo.vstack([bucket_name, create_bucket_btn]) + return (bucket_name, create_bucket_btn) + + +@app.cell +def _(create_bucket, create_bucket_btn, bucket_name): + if create_bucket_btn.value: + create_bucket(bucket_name.value) + return + + +@app.cell(hide_code=True) +def _(mo): + mo.md(r""" + ### List buckets + """) + return + + @app.cell def _(list_buckets): list_buckets()