Deploying to S3 with Metalsmith and Bucketful

When setting up this new site, I wanted to have a dead simple s3 deploy that worked seamlessly with metalsmith. This could be achieved with something as simple as rsync, but I came across bucketful and figured it would work elegantly with my existing metalsmith workflow. This is a quick example of how to set up a metalsmith to s3 deploy.

I've loosely organized my metalsmith chain into 3 tasks: a setup task that is re-used and serve and deploy tasks for local development and s3 deployment respectively. You could use ENV arguments and set up conditionals for the same result, I just prefer node serve and node deploy.

1. Set up your .env

You'll need your AWS key and secret, and you'll probably want to keep those out of your repo. I use dotenv for this, and mot's node implementation has been perfect. Your .env will look something like this:

2. Set up your config and build

I've included an entire example deploy.js below to showcase the setup and config for the s3 credentials and bucketful. It's fairly straightforward. Bucketful accepts your public and secret key, the name of the bucket, and the source for the built files. The metalsmith chain builds the site, and upon successful build, configures and fires bucketful.deploy. After my first accidental deploy, I added the prompt library to create a confirmation. You can check that out in the full source.

3. Deploy the site

If you end up with a setup similar to mine, deploying should be as simple as running node deploy. Bucketful will handle uploading the contents of your build directory and setting the proper permissions for your site to be open to the world.