Owen Conti

How to add Cloudflare Durable Objects to an environment

Posted on under Cloudflare by Owen Conti.

For some reason, Cloudflare doesn't automatically inherit Durable Objects to environments like it does for the rest of the Worker settings. To get around this, you must define the Durable Objects for each environment. Here's an example using the default Counter example Worker:

1# Default environment
2[durable_objects]
3bindings = [{name = "COUNTER", class_name = "CounterTs"}]
4 
5[env.staging]
6name = "durable-objects-test-staging"
7 
8# Need to redefine the binding for the `staging` environment
9[env.staging.durable_objects]
10bindings = [{name = "COUNTER", class_name = "CounterTs"}]

Thanks for reading this article!

Hopefully you found this article useful! If you did, share it on Twitter!

Found an issue with the article? Submit your edits against the repository.