Git Product home page Git Product logo

cloudflare-b2-proxy's Introduction

Cloudflare Worker Backblaze B2 Proxy

Proxy Backblaze S3 compatible API requests, optionally sending notifications to a webhook.

  • Incoming requests must be signed with the same credentials that you configure in the worker. The worker validates the AWS V4 signature on all downstream (incoming) requests and then signs the upstream (outgoing) request.
  • Notifications are dispatched asynchronously to avoid delaying the response to the client.

You can use any S3 SDK or CLI to send requests as long as you set the endpoint URL to the worker endpoint. For example:

% export AWS_ACCESS_KEY_ID=<your b2 application key id>
% export AWS_SECRET_ACCESS_KEY=<your b2 application key> 
% aws s3 cp --endpoint-url https://cloudflare-b2-proxy.<your-subdomain>.workers.dev hello.txt s3://<your-bucket-name>/hello.txt
upload: hello.txt to s3://<your-bucket-name>/hello.txt

Informal testing suggests that there is negligible performance overhead imposed by the signature verification and resigning.

Configuration

You must configure AWS_ACCESS_KEY_ID and AWS_S3_ENDPOINT in wrangler.toml. Configure WEBHOOK_URL if you wish to supply a webhook URL.

[vars]
AWS_ACCESS_KEY_ID = "<your b2 application key id>"
AWS_S3_ENDPOINT = "<your S3 endpoint - e.g. s3.us-west-001.backblazeb2.com >"
WEBHOOK_URL = "<e.g. https://api.example.com/webhook/1 >"

You must also configure AWS_SECRET_ACCESS_KEY as a secret:

echo "<your b2 application key>" | wrangler secret put AWS_SECRET_ACCESS_KEY

Webhook Notification

If you set WEBHOOK_URL, the worker POSTs a JSON payload to that URL for each request that it processes. For example:

{
  "contentLength": "14",
  "contentType": "text/plain",
  "method": "PUT",
  "signatureTimestamp": "20220224T193204Z",
  "status": 200,
  "url": "https://s3.us-west-004.backblazeb2.com/my-private-bucket/tester.txt"
}

You can customize the handleRequest() function to add additional data as you require.

Wrangler

You can use this repository as a template for your own worker using wrangler:

wrangler generate projectname https://github.com/backblaze-b2-samples/cloudflare-b2-proxy

Serverless

To deploy using serverless add a serverless.yml file.

Acknowledgements

Based on https://github.com/obezuk/worker-signed-s3-template

cloudflare-b2-proxy's People

Contributors

jmo-qap avatar metadaddy avatar michaelmcneela avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.