Garrett
CDCloudflare Developers
•Created by Garrett on 2/7/2024 in #general-help
API support for creating R2 S3 credentials
I need to dynamically create S3 style credentials (i.e. api key and key secret combo) to enable writes to a dynamically created R2 bucket. I'm looking to use the API to create these.
I've successfully created a bucket using the API and an auth token configured with the R2 edit permission.
I have not been able to create the S3 style credentials using the API, however.
This interface looks promising: https://developers.cloudflare.com/api/operations/user-api-tokens-create-token
However, the result does not contain (at least per the docs) the S3 creds - it only contains the token value. ALSO, I'm unable to configure an auth token with the permission to use this API call in the first place.
Under https://dash.cloudflare.com/profile/api-tokens I can add permissions for a token. However, I don't see a permission that allows editing/creating API tokens.
To summarize:
1. How can I use the API to create an API token? This requires granting permission for this, which I haven't been able to do.
2. How can I create an API token that returns S3 style credentials for editing an R2 bucket?
5 replies
CDCloudflare Developers
•Created by Garrett on 2/2/2024 in #general-help
Get R2Bucket (or similar) by bucket name in API
R2 bucket bindings are statically defined in wranger.toml. I need to access buckets by name in code. Buckets are created dynamically and so a static definition per worker won't work. Something like this would be ideal: env.BUCKETS.get(buckerName) -> R2Bucket | null.
If I can just use fetch from the worker that'd be fine - but I'd like to make the requests within the CF environment as efficiently as possibe.
2 replies