Public Beta: Remote bindings in local development #9660
Replies: 5 comments 9 replies
-
Oh, this is gonna be lit🔥🔥 |
Beta Was this translation helpful? Give feedback.
-
This is ironically an amazing solution. AMAZING DELIVERY !!! And as always, thanks a million. |
Beta Was this translation helpful? Give feedback.
-
Is this actually live? I'm on 4.20.3... |
Beta Was this translation helpful? Give feedback.
-
This is a great help for R2. Your problem statement in the background section describes our use case. And bonus, since we can stop using Just to clarify, remote bindings do not support Durable Objects yet, correct? We definitely would also use DO remote bindings. Our local and PR preview environments share all of the same resources, so it's awkward when DO state mismatches between them and we need to re-seed PR previews. But the R2 solve is already great, since our PR Previews had lots of 404's from missing assets that were added in local dev. |
Beta Was this translation helpful? Give feedback.
-
Just a question that might have an obvious answer: If I want to switch between remote vs non-remote based on my local "environment", how would I do this? I know with Vite plugin I can dynamically generate the vite config and therefor point to another wrangler.jsonc from |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all 👋
We’re excited to introduce beta support for remote bindings for local development, allowing you to connect to deployed resources like R2 buckets and D1 databases – all while running your Worker code on your local machine. This means you can test your local code changes against real data and services, without the overhead of deploying for each iteration.
You can try out remote bindings for local development today with:
wrangler dev --x-remote-bindings
command.Example configuration
Remote bindings can be specified on a per-binding basis using
experimental_remote: true
.Get started today by reviewing our documentation for remote bindings, with special attention to the recommended remote bindings and unsupported remote bindings.
Background
Bindings are a core part of Cloudflare Workers, allowing your Worker to access and perform operations against other Cloudflare resources (like KV namespaces, R2 buckets, D1 databases, Queues, Durable Objects, etc) without needing to manage secret keys and tokens. Unlike traditional environment variables (which are typically strings), bindings are live objects with methods you can call directly to perform actions. In your Worker code, these are accessed via the
env
object (such asenv.MY_KV
). Whether your code is running in production or running locally, your Worker code interacts with these bindings using the exact same API calls, likeenv.MY_KV.put()
. The difference is whether those bindings are interacting with their deployed counterparts, or local simulations.How bindings work in local development
When you run
wrangler dev
(orvite dev
if using the Cloudflare Vite plugin), the Miniflare simulator boots up and executes your Worker code using the same runtime used in production, workerd . To make sure calls on bindings can succeed and behave as expected, Miniflare creates locally simulated resources that a call likeenv.MY_KV.put()
can interact with.However, this locally simulated KV is initially empty – you need to populate it with data. You can do this using Wrangler commands, but this manual process breaks down in real-world scenarios:
staging
to test a change, your local setup won’t know about it.Previously, our answer to these problems was remote development (via
wrangler dev --remote
), which uploads all of your Worker code to Cloudflare’s network so that you can test against real resources. However,wrangler dev --remote
comes at the cost of a much slower development cycle: you need to wait for your entire Worker to get deployed to a remote environment just to see if your change works as expected. For most users,wrangler dev --remote
is even more impractical than seeding local resources, since remote execution of your Worker can slow down the development loop.Introducing: Remote bindings for local development
Remote bindings bring the best of both: the speed of local code execution with the realism of interacting with live, deployed resources. You can specify which bindings should connect to their deployed counterparts in Wrangler configuration, and when you start your local development server, all calls to that binding will be proxied to the remote resource.
This means:
Workers for Platforms users can also configure
experimental_remote:true
in dispatch namespace binding definitions:This allows you to run your dynamic dispatch Worker locally, while connecting it to your remote dispatch namespace binding. You can then test changes to your core dispatching logic against real, deployed user Workers.
Known limitations
Open Questions
Does configuring this setting in the binding definition feel intuitive? We originally went back and forth on whether specifying that a binding should target the deployed resource should be configured in something like
.dev.vars
/.env
, since you’re really overriding local dev behavior.MY_R2=@r2_bucket:my_r2_preview_bucket_name
Will configuring remote bindings in Wrangler config be difficult for teams? Since teams are often sharing Wrangler configuration, we can imagine that each developer might have different preferences for which bindings should connect remotely. Needing to remember to toggle
experimental_remote
back and forth before committing changes could get really tedious – another reason we thought about configuring this in something like.dev.vars
/.env
.For those building CLIs/develop tools for our platform: Some Workers for Platforms customers make CLIs either wrapping around Wrangler or custom, and we’d love to hear about your experience / if anything is missing from our documented API. Similarly, there are a number of developer tools building on our platform that want to provide a local dev experience, and would love to hear the ways in which you use our API for proxying remote connections during local dev.
Call to action
This is an early beta, and your feedback is critical to helping us refine the experience. After you've had a chance to try it out, please share your thoughts with us below on this discussion topic.
We are particularly interested in:
Reporting any bugs or unexpected behavior you encounter. Please open an issue with as much detail as possible.
Feedback on what you like about this workflow. Does it solve a real problem for you? What use-cases have you uncovered that we didn’t anticipate?
Feedback on what rough edges we missed. Are there parts of the experience that feel confusing or could be improved?
If you’d like to book time to give feedback to our team directly, we’d love to chat! Feel free to book any open time on my calendar.
Beta Was this translation helpful? Give feedback.
All reactions