Skip to content

Commit a2a9a45

Browse files
add section on how to use durable objects with remote resources
1 parent 6935eca commit a2a9a45

File tree

1 file changed

+27
-1
lines changed
  • src/content/docs/workers/development-testing

1 file changed

+27
-1
lines changed

src/content/docs/workers/development-testing/index.mdx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ Certain bindings are not supported for remote connections during local developme
295295

296296
If `experimental_remote: true` is specified in Wrangler configuration for any of the following unsupported binding types, Cloudflare **will issue an error**. See [all supported and unsupported bindings for remote bindings](/workers/development-testing/bindings-per-env/).
297297

298-
- [**Durable Objects**](/workers/wrangler/configuration/#durable-objects): Enabling remote connections for Durable Objects may be supported in the future, but currently will always run locally.
298+
- [**Durable Objects**](/workers/wrangler/configuration/#durable-objects): Enabling remote connections for Durable Objects may be supported in the future, but currently will always run locally. Using Durable Objects in combination with remote bindings is however possible
299+
as illustrated in the [Durable Objects usage section](#durable-objects-usage-with-remote-resources) below.
299300

300301
- [**RPC on service bindings**](/workers/runtime-apis/bindings/service-bindings/rpc/): While you can make `fetch()` calls on remote service bindings, you cannot currently call RPC methods on remote service bindings.
301302

@@ -319,6 +320,31 @@ If `experimental_remote: true` is specified in Wrangler configuration for any of
319320
If you have use-cases for connecting to any of the remote resources above, please [open a feature request](https://github.com/cloudflare/workers-sdk/issues) in our [`workers-sdk` repository](https://github.com/cloudflare/workers-sdk).
320321
:::
321322

323+
#### Durable Objects Usage with Remote Resources
324+
325+
While Durable Objects cannot currently run in remote mode, you can still use them during local development and have them interact with remote resources.
326+
327+
There are two main approaches for this:
328+
329+
- **Local Durable Objects with remote bindings:**
330+
331+
When you enable remote mode for a binding in your [Wrangler configuration](/workers/wrangler/configuration), both your main Worker and any local Durable Object
332+
can make use of it. This allows Durable Objects to interact with remote resources during local development.
333+
334+
- **Remote Durable Objects with local Workers:**
335+
336+
You can run Durable Objects remotely from a Worker using [`wrangler dev --remote`](/workers/wrangler/commands/#dev) and have them interact with local Workers
337+
running on your machine by leveraging Wrangler's [Multiple dev commands](./multi-workers/#multiple-dev-commands) feature.
338+
339+
To do this:
340+
341+
- Start your remote Worker (which contains the Durable Object) using `wrangler dev --remote`.
342+
343+
- In your local Workers' configuration, set the Durable Object's [`script_name`](/workers/wrangler/configuration/#durable-objects) to the name of the remote Worker.
344+
345+
- Run your local Workers with `wrangler dev` to connect to the remote Durable Object.
346+
347+
322348
### Important Considerations
323349

324350
- **Data modification**: Operations (writes, deletes, updates) on bindings connected remotely will affect your actual data in the targeted Cloudflare resource (be it preview or production).

0 commit comments

Comments
 (0)