Skip to content

S3 Compatible Vendors

Daniel Lamando edited this page May 15, 2022 · 5 revisions

Various vendors expose their own S3-like APIs, usually branded as an Object Storage service.

If you want to connect to a service that has a URL like <region>.service.com, then the S3CompatibleEndpointResolver provided by /x/aws_api should do the trick.

You can import the class alongside the main ApiFactory class:

import {
  ApiFactory,
  S3CompatibleEndpointResolver,
} from "https://deno.land/x/aws_api/client/mod.ts";

import { S3 } from "https://deno.land/x/aws_api/services/s3/mod.ts";

Configuration & Credentials

Note that /x/aws_api will continue to look at AWS_* environment variables for credentials and region configuration. So you'll still use AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.

If you want to change the environment variable names, provide your own credential structure:

export const doApi = new ApiFactory({
  endpointResolver: new S3CompatibleEndpointResolver('digitaloceanspaces.com'),
  credentials: {
    awsAccessKeyId: Deno.env.get("DO_ACCESS_KEY_ID")!,
    awsSecretKey: Deno.env.get("DO_SECRET_ACCESS_KEY")!,
  },
  region: Deno.env.get("DO_REGION"),
}).makeNew(S3);

Alternatively, create an EnvironmentCredentials instance:

export const doApi = new ApiFactory({
  endpointResolver: new S3CompatibleEndpointResolver('digitaloceanspaces.com'),
  credentialProvider: new EnvironmentCredentials('DO'),
  region: Deno.env.get("DO_REGION"),
}).makeNew(S3);

Known Providers

Below are a few vendors and some example code for each.

NOTE: Only the endpoints have been confirmed for many of these! If you have success with one, or if you have errors, please report either way so documentation can be updated.

Digital Ocean's "Spaces"

The regions look like nyc3, sfo2, fra1, etc.

const api = new ApiFactory({
  endpointResolver: new S3CompatibleEndpointResolver('digitaloceanspaces.com'),
}).makeNew(S3);

Functionality: ❓ Untested

Linode's "Objects"

The regions are similar to AWS's: ap-south-1, eu-central-1, us-east-1, etc.

const api = new ApiFactory({
  endpointResolver: new S3CompatibleEndpointResolver('linodeobjects.com'),
}).makeNew(S3);

Functionality: ❓ Untested

Vultr's "Objects"

There's only one region, so it's specified inline below.

const api = new ApiFactory({
  endpointResolver: new S3CompatibleEndpointResolver('vultrobjects.com'),
  region: 'ewr1', // the only region that exists as of writing this
}).makeNew(S3);

Functionality: ✔️ Tested

Backblaze's "B2"

Backblaze has a different URL structure which isn't accounted for by the S3 resolver. So for now used fixedEndpoint:

const api = new ApiFactory({
  fixedEndpoint: "https://s3.us-west-001.backblazeb2.com",
  region: "us-west-001",
}).makeNew(S3);

Functionality:

Cloudflare's "R2" Beta

As of writing, R2 requires path-style routing, otherwise a 500 is returned. The buckets are also scoped to a per-account namespace and there is no choice of regions. This is a good fit for fixedEndpoint:

const api = new ApiFactory({
  fixedEndpoint: `https://${Deno.env.get('R2_ACCOUNT')}.r2.cloudflarestorage.com`,
  region: 'auto', // cloudflare r2 only has one region
}).makeNew(S3);

Functionality:

  • ✔️ Basic operations work
  • ❓ R2 itself is still in beta
Clone this wiki locally