Is there any way I could setup bindings on a worker for r2_buckets from different accounts?

In my worker.toml, instead of having something like
r2_buckets = [
{ binding = "STORAGE_1", bucket_name = "storage", preview_bucket_name = "Storage (Private)" },
{ binding = "STORAGE_1_PUBLIC", bucket_name = "storage-public", preview_bucket_name = "Storage (Public)" },
]
r2_buckets = [
{ binding = "STORAGE_1", bucket_name = "storage", preview_bucket_name = "Storage (Private)" },
{ binding = "STORAGE_1_PUBLIC", bucket_name = "storage-public", preview_bucket_name = "Storage (Public)" },
]
The bucket_name is merely for the buckets in the account where this bucket will be deployed. I am wondering if there is a way to bind buckets from other accounts from within the same worker. (Without using the typical API key for every request) The goal is to be able to take advantage of the bindings usefulness isntead of having to manually craft a POST request for everything I am doing. Just wondering if there is someway to do this within wrangler.toml or if I have to end up doing something like the following:
export const buckets = [
{
account_id: '___ACCOUNT____ID___1', // for a given email 1
buckets: [
{ bucketName: 'storage', binding = "STORAGE_1" },
{ bucketName: 'storage-public', binding: 'STORAGE_1_PUBLIC' },
]
},
{
account_id: '___ACCOUNT____ID___2', // for a given email 2
buckets: [
{ bucketName: 'storage', binding = "STORAGE_2" },
{ bucketName: 'storage-public', binding: 'STORAGE_2_PUBLIC' },
]
},
export const buckets = [
{
account_id: '___ACCOUNT____ID___1', // for a given email 1
buckets: [
{ bucketName: 'storage', binding = "STORAGE_1" },
{ bucketName: 'storage-public', binding: 'STORAGE_1_PUBLIC' },
]
},
{
account_id: '___ACCOUNT____ID___2', // for a given email 2
buckets: [
{ bucketName: 'storage', binding = "STORAGE_2" },
{ bucketName: 'storage-public', binding: 'STORAGE_2_PUBLIC' },
]
},
This approach described above would manually require me to use an api key with permissions to email 1 and 2, and craft those requests by hand, as opposed to just using the bindings that "just work" Any thoughts on this would be very helpful and appreciated, thanks!
3 Replies
Migmac
MigmacOP8mo ago
This of course assumes the account on which this worker is deployed to has access to those other accounts. Even If there is an API key I should set, wondering if there is an automated way
James
James8mo ago
I'm not aware of any way for a worker to access resources via binding in another account. The only way I can think to do this would be via the API directly.
Migmac
MigmacOP8mo ago
Lots of work lies ahead then! Thanks nonetheless =]
Want results from more Discord servers?
Add your server