Best way to use Cloudflare R2 and presigned URLs with Haskell

I’m looking to use Cloudflare R2 (mostly S3-compatible storage service) for a tool I’d like to build. One of the appeals of R2 is its lack of data egress fees, allowing billing to be much more predictable.

One issue I have is that while R2 does support presigned URLs for enabling clients to directly upload/download from your otherwise private buckets, the means of using this feature all seem to be “use an AWS SDK or the AWS CLI to generate the presigned URLs”.

There are S3 SDKs for Haskell, but not all of them support presigned URLs and those that do seem to bake in assumptions about AWS. For example the presignURL function in amazonka takes a Region as a parameter, which is a sum type that only supports actual AWS regions. Not sure is this is technically a breaking/blocking issue for generating presigned URLs, as the JavaScript SDKs don’t seem to care about the region at all when generating them.

Other Haskell S3 libaries:

  • hS3
    • Seems to support making a presigned URL and is much more stringly typed
    • Hasn’t been updated since 2017
  • S3
    • Doesn’t seem to support presigned URLs at all
  • s3-signer
    • Fields that go into the signing function are stringly-typed, similar to hS3
    • Hasn’t been materially updated since about 2018

If anyone has luck with using Haskell to generate presigned URLs for any non-AWS implementation of S3, or with Cloudflare R2 specifically, please let me know. I’d love to hear from you before I go down the path of trying to get this working.

2 Likes