Can I assign a worker binding during runtime?

Provided I have the account_id and the bucketName as well as an api key with the ability to do this, can I dynamically assign a binding to a worker on runtime?
7 Replies
Migmac
MigmacOP8mo ago
The goal is to not use the API and use something like: const bucket = env[data.params.bucket] having that be the same as a normal regular binding set in wrangler.toml
Erisa
Erisa8mo ago
Dynamic bindings is something that isn't possible today, but is being worked on
Migmac
MigmacOP8mo ago
Thanks! Do you know if that is something that is coming in the near future (a few months) or later? If later I might have to use the api key and manually do every request the API way .-. Just wondering so I can better organize myself!
Erisa
Erisa8mo ago
There isn't an ETA available that I could share, it's just being worked on and will release when it's ready. Sorry for the trouble there. For R2 I would suggest using the S3-compatible API within the Worker using e.g. aws4fetch or the AWS SDK
Migmac
MigmacOP8mo ago
I appreciate your candor. Thank you nonetheless! Also, is there a particular way I can get notified when it is ready? (Besides following the discord)
Erisa
Erisa8mo ago
It should be posted on https://developers.cloudflare.com/changelog or https://blog.cloudflare.com/ and you can subscribe to updates for specific products with the /subscribe command here (I imagine this may fall under the Workers one) I don't believe there's a way to be notified for that feature specifically
Migmac
MigmacOP8mo ago
PS: My ultimate goal here is to be able to access r2 buckets from different accounts within the same worker. As a suggestion, if this were to be possible through the wrangler.toml file, that would be heaven for me! Thanks! (As some further context) I would like to be able to manage a few of my client's r2 buckets from within the same place. Hope this helps May you have a wonderful day and thanks again for your assistance! =] i'd imagine extending this:
r2_buckets = [
{ binding = "BUCKET_1", bucket_name = "bucket-1", preview_bucket_name = "Bucket One" },
]
r2_buckets = [
{ binding = "BUCKET_1", bucket_name = "bucket-1", preview_bucket_name = "Bucket One" },
]
into something like:
r2_buckets = [
{ account_id = "12312312313abcabc", binding = "BUCKET_1", bucket_name = "bucket-1", preview_bucket_name = "Bucket One" },
]
r2_buckets = [
{ account_id = "12312312313abcabc", binding = "BUCKET_1", bucket_name = "bucket-1", preview_bucket_name = "Bucket One" },
]
Want results from more Discord servers?
Add your server