Host on spaces starting with $200 credit

Digital Ocean* has a product called Spaces, which is a drop in replacement for the majority of uses of Amazon’s S3. Including static website hosting.

I’ve had to turn to Spaces instead of S3 because I’ve got technicallyshane.com managed by DO, because then they can point all sorts of subdomains to my droplets and other services. I really just wanted a quick place for me to put my bookmarklet to filter hover.com domains by price.

Pros vs S3:

  • S3’s UI has gotten gradually more complex, which DO gives a fresh edge too.
  • S3’s IAM permissions is a complex overhead for just a silly static website.
  • My DNS doesn’t have to change. (No need to pay for Route 53.)
  • You can still use the S3 SDK.
  • CDN for free, with one button.
  • Subdomain per-bucket set up with one button.

Cons vs S3:

  • $5 per month, right from the start. You get unlimited “buckets” and a cumulative total of 250Gb included in that though. 1TB bandwidth.

The change from S3 to Spaces is as easy as adding one line:

const fs = require('fs');
const AWS = require('aws-sdk')

const spacesEndpoint = new AWS.Endpoint('fra1.digitaloceanspaces.com');
const s3 = new AWS.S3({
  endpoint: spacesEndpoint,
  accessKeyId: process.env.DEPLOY_KEY_ID,
  secretAccessKey: process.env.DEPLOY_KEY
});

const remoteDirectory = "hover";
const build = `${__dirname}/../build`;

fs.readdirSync(build).forEach(file => {
  if (file[0] == '.') return;

  var params = {
    Body: fs.readFileSync(`${build}/${file}`, "utf-8"),
    Bucket: 'name-of-your-space',
    Key: `${remoteDirectory}/${file}`,
    ACL: "public-read",
    ContentDisposition: "inline",
    ContentType: "text/html",
  };

  s3.putObject(params, function(err, data) {
    if (err) console.log(err, err.stack);
    else     console.log(data);
  });
});

* This is an affiliate link that’ll give you $200 credit to spend in 60 days. Two months free Spaces, plus a bunch of droplets, I guess.