Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/r2-data-catalog/configuration.md
1# Configuration23How to enable R2 Data Catalog and configure authentication.45## Prerequisites67- Cloudflare account with [R2 subscription](https://developers.cloudflare.com/r2/pricing/)8- R2 bucket created9- Access to Cloudflare dashboard or Wrangler CLI1011## Enable Catalog on Bucket1213Choose one method:1415### Via Wrangler (Recommended)1617```bash18npx wrangler r2 bucket catalog enable <BUCKET_NAME>19```2021**Output:**22```23✅ Data Catalog enabled for bucket 'my-bucket'24Catalog URI: https://<account-id>.r2.cloudflarestorage.com/iceberg/my-bucket25Warehouse: my-bucket26```2728### Via Dashboard29301. Navigate to **R2** → Select your bucket → **Settings** tab312. Scroll to "R2 Data Catalog" section → Click **Enable**323. Note the **Catalog URI** and **Warehouse name** shown3334**Result:**35- Catalog URI: `https://<account-id>.r2.cloudflarestorage.com/iceberg/<bucket-name>`36- Warehouse: `<bucket-name>` (same as bucket name)3738### Via API (Programmatic)3940```bash41curl -X POST \42"https://api.cloudflare.com/client/v4/accounts/<account-id>/r2/buckets/<bucket>/catalog" \43-H "Authorization: Bearer <api-token>" \44-H "Content-Type: application/json"45```4647**Response:**48```json49{50"result": {51"catalog_uri": "https://<account-id>.r2.cloudflarestorage.com/iceberg/<bucket>",52"warehouse": "<bucket>"53},54"success": true55}56```5758## Check Catalog Status5960```bash61npx wrangler r2 bucket catalog status <BUCKET_NAME>62```6364**Output:**65```66Catalog Status: enabled67Catalog URI: https://<account-id>.r2.cloudflarestorage.com/iceberg/my-bucket68Warehouse: my-bucket69```7071## Disable Catalog (If Needed)7273```bash74npx wrangler r2 bucket catalog disable <BUCKET_NAME>75```7677⚠️ **Warning:** Disabling does NOT delete tables/data. Files remain in bucket. Metadata becomes inaccessible until re-enabled.7879## API Token Creation8081R2 Data Catalog requires API token with **both** R2 Storage + R2 Data Catalog permissions.8283### Dashboard Method (Recommended)84851. Go to **R2** → **Manage R2 API Tokens** → **Create API Token**862. Select permission level:87- **Admin Read & Write** - Full catalog + storage access (read/write)88- **Admin Read only** - Read-only access (for query engines)893. Copy token value immediately (shown only once)9091**Permission groups included:**92- `Workers R2 Data Catalog Write` (or Read)93- `Workers R2 Storage Bucket Item Write` (or Read)9495### API Method (Programmatic)9697Use Cloudflare API to create tokens programmatically. Required permissions:98- `Workers R2 Data Catalog Write` (or Read)99- `Workers R2 Storage Bucket Item Write` (or Read)100101## Client Configuration102103### PyIceberg104105```python106from pyiceberg.catalog.rest import RestCatalog107108catalog = RestCatalog(109name="my_catalog",110warehouse="<bucket-name>", # Same as bucket name111uri="<catalog-uri>", # From enable command112token="<api-token>", # From token creation113)114```115116**Full example with credentials:**117```python118import os119from pyiceberg.catalog.rest import RestCatalog120121# Store credentials in environment variables122WAREHOUSE = os.getenv("R2_WAREHOUSE") # e.g., "my-bucket"123CATALOG_URI = os.getenv("R2_CATALOG_URI") # e.g., "https://abc123.r2.cloudflarestorage.com/iceberg/my-bucket"124TOKEN = os.getenv("R2_TOKEN") # API token125126catalog = RestCatalog(127name="r2_catalog",128warehouse=WAREHOUSE,129uri=CATALOG_URI,130token=TOKEN,131)132133# Test connection134print(catalog.list_namespaces())135```136137### Spark / Trino / DuckDB138139See [patterns.md](patterns.md) for integration examples with other query engines.140141## Connection String Format142143For quick reference:144145```146Catalog URI: https://<account-id>.r2.cloudflarestorage.com/iceberg/<bucket>147Warehouse: <bucket-name>148Token: <r2-api-token>149```150151**Where to find values:**152153| Value | Source |154|-------|--------|155| `<account-id>` | Dashboard URL or `wrangler whoami` |156| `<bucket>` | R2 bucket name |157| Catalog URI | Output from `wrangler r2 bucket catalog enable` |158| Token | R2 API Token creation page |159160## Security Best Practices1611621. **Store tokens securely** - Use environment variables or secret managers, never hardcode1632. **Use least privilege** - Read-only tokens for query engines, write tokens only where needed1643. **Rotate tokens regularly** - Create new tokens, test, then revoke old ones1654. **One token per application** - Easier to track and revoke if compromised1665. **Monitor token usage** - Check R2 analytics for unexpected patterns1676. **Bucket-scoped tokens** - Create tokens per bucket, not account-wide168169## Environment Variables Pattern170171```bash172# .env (never commit)173R2_CATALOG_URI=https://<account-id>.r2.cloudflarestorage.com/iceberg/<bucket>174R2_WAREHOUSE=<bucket-name>175R2_TOKEN=<api-token>176```177178```python179import os180from pyiceberg.catalog.rest import RestCatalog181182catalog = RestCatalog(183name="r2",184uri=os.getenv("R2_CATALOG_URI"),185warehouse=os.getenv("R2_WAREHOUSE"),186token=os.getenv("R2_TOKEN"),187)188```189190## Troubleshooting191192| Problem | Solution |193|---------|----------|194| 404 "catalog not found" | Run `wrangler r2 bucket catalog enable <bucket>` |195| 401 "unauthorized" | Check token has both Catalog + Storage permissions |196| 403 on data files | Token needs both permission groups |197198See [gotchas.md](gotchas.md) for detailed troubleshooting.199