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/bindings/configuration.md
1# Binding Configuration Reference23## Storage Bindings45```jsonc6{7"kv_namespaces": [{ "binding": "MY_KV", "id": "..." }],8"r2_buckets": [{ "binding": "MY_BUCKET", "bucket_name": "my-bucket" }],9"d1_databases": [{ "binding": "DB", "database_name": "my-db", "database_id": "..." }],10"durable_objects": { "bindings": [{ "name": "MY_DO", "class_name": "MyDO" }] },11"vectorize": [{ "binding": "VECTORIZE", "index_name": "my-index" }],12"queues": { "producers": [{ "binding": "MY_QUEUE", "queue": "my-queue" }] }13}14```1516**Create commands:**17```bash18npx wrangler kv namespace create MY_KV19npx wrangler r2 bucket create my-bucket20npx wrangler d1 create my-db21npx wrangler vectorize create my-index --dimensions=768 --metric=cosine22npx wrangler queues create my-queue2324# List existing resources25npx wrangler kv namespace list26npx wrangler r2 bucket list27npx wrangler d1 list28npx wrangler vectorize list29npx wrangler queues list30```3132## Compute Bindings3334```jsonc35{36"services": [{37"binding": "MY_SERVICE",38"service": "other-worker",39"environment": "production" // Optional: target specific env40}],41"ai": { "binding": "AI" },42"browser": { "binding": "BROWSER" },43"workflows": [{ "binding": "MY_WORKFLOW", "name": "my-workflow" }]44}45```4647**Create workflows:**48```bash49npx wrangler workflows create my-workflow50```5152## Platform Bindings5354```jsonc55{56"analytics_engine_datasets": [{ "binding": "ANALYTICS" }],57"mtls_certificates": [{ "binding": "MY_CERT", "certificate_id": "..." }],58"hyperdrive": [{ "binding": "HYPERDRIVE", "id": "..." }],59"unsafe": {60"bindings": [{ "name": "RATE_LIMITER", "type": "ratelimit", "namespace_id": "..." }]61}62}63```6465## Configuration Bindings6667```jsonc68{69"vars": {70"API_URL": "https://api.example.com",71"MAX_RETRIES": "3"72},73"text_blobs": { "MY_TEXT": "./data/template.html" },74"data_blobs": { "MY_DATA": "./data/config.bin" },75"wasm_modules": { "MY_WASM": "./build/module.wasm" }76}77```7879**Secrets (never in config):**80```bash81npx wrangler secret put API_KEY82```8384## Environment-Specific Configuration8586```jsonc87{88"name": "my-worker",89"vars": { "ENV": "production" },90"kv_namespaces": [{ "binding": "CACHE", "id": "prod-kv-id" }],9192"env": {93"staging": {94"vars": { "ENV": "staging" },95"kv_namespaces": [{ "binding": "CACHE", "id": "staging-kv-id" }]96}97}98}99```100101**Deploy:**102```bash103npx wrangler deploy # Production104npx wrangler deploy --env staging105```106107## Local Development108109```jsonc110{111"kv_namespaces": [{112"binding": "MY_KV",113"id": "prod-id",114"preview_id": "dev-id" // Used in wrangler dev115}]116}117```118119**Or use remote:**120```bash121npx wrangler dev --remote # Uses production bindings122```123124## Complete Example125126```jsonc127{128"$schema": "./node_modules/wrangler/config-schema.json",129"name": "my-app",130"main": "src/index.ts",131"compatibility_date": "2025-01-01",132133"vars": { "API_URL": "https://api.example.com" },134"kv_namespaces": [{ "binding": "CACHE", "id": "abc123" }],135"r2_buckets": [{ "binding": "ASSETS", "bucket_name": "my-assets" }],136"d1_databases": [{ "binding": "DB", "database_name": "my-db", "database_id": "xyz789" }],137"services": [{ "binding": "AUTH", "service": "auth-worker" }],138"ai": { "binding": "AI" }139}140```141142## Binding-Specific Configuration143144### Durable Objects with Class Export145146```jsonc147{148"durable_objects": {149"bindings": [150{ "name": "COUNTER", "class_name": "Counter", "script_name": "my-worker" }151]152}153}154```155156```typescript157// In same Worker or script_name Worker158export class Counter {159constructor(private state: DurableObjectState, private env: Env) {}160async fetch(request: Request) { /* ... */ }161}162```163164### Queue Consumers165166```jsonc167{168"queues": {169"producers": [{ "binding": "MY_QUEUE", "queue": "my-queue" }],170"consumers": [{ "queue": "my-queue", "max_batch_size": 10 }]171}172}173```174175Queue consumer handler: `export default { async queue(batch, env) { /* process batch.messages */ } }`176177## Key Points178179- **64 binding limit** (all types combined)180- **Secrets**: Always use `wrangler secret put`, never commit181- **Types**: Run `npx wrangler types` after config changes182- **Environments**: Use `env` field for staging/production variants183- **Development**: Use `preview_id` or `--remote` flag184- **IDs vs Names**: Some bindings use `id` (KV, D1), others use `name` (R2, Queues)185186## See Also187188- [Wrangler Configuration](https://developers.cloudflare.com/workers/wrangler/configuration/)