An sbt plugin for deploying a static website to s3 programmatically.
- An AWS account with permissions for accessing and modifying S3 resources. Make sure you have configured your access
(for example by setting your credentials in
~/.aws/credentials
and your region in~/.aws/config
. - An SBT project, using the sbt-web plugin
- In
[yoursbtproject]/project/plugins.sbt
add the following:
resolvers ++= Resolver.sonatypeOssRepos("releases")
addSbtPlugin("nl.wwbakker" % "sbt-deploy-static-website-to-s3" % "1.3")
// Add sbt-web if it isn't added to your project already.
addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.4.4")
- SbtWeb needs to be enabled. When SbtWeb is enabled, this plugin's
tasks will be automatically made available. To enable SbtWeb, add
.enablePlugins(SbtWeb)
to yourbuild.sbt
:
lazy val root = (project in file("."))
.settings(
name := "your-project",
organization := "org.example"
).enablePlugins(SbtWeb)
- Then in your project's
build.sbt
set the following properties
// Configure your bucket name here. The bucketname will be visible in the URL.
// When you want to use S3 to host a website from your domain, be sure to mirror
// the domain name in your bucket name
DeployStaticWebsiteToS3 / bucketName := Some("www.mywebsite.com")
// OPTIONAL: default is index.html
DeployStaticWebsiteToS3 / indexDocument := "index.html"
// OPTIONAL: default is unset
DeployStaticWebsiteToS3 / errorDocument := "error.html"
Once you have configured the plugin in your project you have the following tasks available in your project:
deploy-static-website-to-s3:createS3Bucket
: Creates an empty s3 bucket, configured for use for static website.deploy-static-website-to-s3:deployToS3
: Uploads your website's files and deletes files in the bucket that do not pertain to your site.deploy-static-website-to-s3:undeployFromS3
: Removes all files from the configured S3 bucket.deploy-static-website-to-s3:deleteS3Bucket
: Deletes the configured S3 bucket.
As this plugin manages your S3 buckets, be careful. Creating buckets and uploading files can incur costs (AWS will charge for storing and serving data on S3). Deleting your files on S3 without having a backup can cause you to lose files.