• Stars
    star
    510
  • Rank 86,627 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple tool to deploy static websites to Amazon S3 and CloudFront with Gzip and custom headers support (e.g. "Cache-Control")

s3deploy

Project status: active – The project has reached a stable, usable state and is being actively developed. GoDoc Test Go Report Card codecov Release

A simple tool to deploy static websites to Amazon S3 and CloudFront with Gzip and custom headers support (e.g. "Cache-Control"). It uses ETag hashes to check if a file has changed, which makes it optimal in combination with static site generators like Hugo.

Install

Pre-built binaries can be found here.

s3deploy is a Go application, so you can also install the latest version with:

 go install github.com/bep/s3deploy/v2@latest

To install on MacOS using Homebrew:

brew install bep/tap/s3deploy

Note The brew tap above currently stops at v2.8.1; see this issue for more info.

Note that s3deploy is a perfect tool to use with a continuous integration tool such as CircleCI. See this for a tutorial that uses s3deploy with CircleCI.

Configuration

Flags

The list of flags from running s3deploy -h:

-V print version and exit
-acl string
    provide an ACL for uploaded objects. to make objects public, set to 'public-read'. all possible values are listed here: https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl (default "private")
-bucket string
    destination bucket name on AWS
-config string
    optional config file (default ".s3deploy.yml")
-distribution-id value
    optional CDN distribution ID for cache invalidation, repeat flag for multiple distributions
-endpoint-url url
	optional AWS endpoint URL override
-force
    upload even if the etags match
-h	help
-ignore string
    regexp pattern for ignoring files
-key string
    access key ID for AWS
-max-delete int
    maximum number of files to delete per deploy (default 256)
-path string
    optional bucket sub path
-public-access
    DEPRECATED: please set -acl='public-read'
-quiet
    enable silent mode
-region string
    name of AWS region
-secret string
    secret access key for AWS
-source string
    path of files to upload (default ".")
-try
    trial run, no remote updates
-v	enable verbose logging
-workers int
    number of workers to upload files (default -1)

The flags can be set in one of (in priority order):

  1. As a flag, e.g. s3deploy -path public/
  2. As an OS environment variable prefixed with S3DEPLOY_, e.g. S3DEPLOY_PATH="public/".
  3. As a key/value in .s3deploy.yml, e.g. path: "public/"
  4. For key and secret resolution, the OS environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY (and AWS_SESSION_TOKEN) will also be checked. This way you don't need to do any special to make it work with AWS Vault and similar tools.

Environment variable expressions in .s3deploy.yml on the form ${VAR} will be expanded before it's parsed:

path: "${MYVARS_PATH}"
max-delete: "${MYVARS_MAX_DELETE@U}"

Note the special @U (Unquoute) syntax for the int field.

Routes

The .s3deploy.yml configuration file can also contain one or more routes. A route matches files given a regexp. Each route can apply:

header : Header values, the most notable is probably Cache-Control. Note that the list of system-defined metadata that S3 currently supports and returns as HTTP headers when hosting a static site is very short. If you have more advanced requirements (e.g. security headers), see this comment.

gzip : Set to true to gzip the content when stored in S3. This will also set the correct Content-Encoding when fetching the object from S3.

Example:

routes:
    - route: "^.+\\.(js|css|svg|ttf)$"
      #  cache static assets for 1 year.
      headers:
         Cache-Control: "max-age=31536000, no-transform, public"
      gzip: true
    - route: "^.+\\.(png|jpg)$"
      headers:
         Cache-Control: "max-age=31536000, no-transform, public"
      gzip: false
    - route: "^.+\\.(html|xml|json)$"
      gzip: true

Global AWS Configuration

See https://docs.aws.amazon.com/sdk-for-go/api/aws/session/#hdr-Sessions_from_Shared_Config

The AWS SDK will fall back to credentials from ~/.aws/credentials.

If you set the AWS_SDK_LOAD_CONFIG environment variable, it will also load shared config from ~/.aws/config where you can set the global region to use if not provided etc.

Example IAM Policy

{
   "Version": "2012-10-17",
   "Statement":[
      {
         "Effect":"Allow",
         "Action":[
            "s3:ListBucket",
            "s3:GetBucketLocation"
         ],
         "Resource":"arn:aws:s3:::<bucketname>"
      },
      {
         "Effect":"Allow",
         "Action":[
            "s3:PutObject",
            "s3:PutObjectAcl",
            "s3:DeleteObject"
         ],
         "Resource":"arn:aws:s3:::<bucketname>/*"
      }
   ]
}

Replace with your own.

CloudFront CDN Cache Invalidation

If you have configured CloudFront CDN in front of your S3 bucket, you can supply the distribution-id as a flag. This will make sure to invalidate the cache for the updated files after the deployment to S3. Note that the AWS user must have the needed access rights.

Note that CloudFront allows 1,000 paths per month at no charge, so S3deploy tries to be smart about the invalidation strategy; we try to reduce the number of paths to 8. If that isn't possible, we will fall back to a full invalidation, e.g. "/*".

Example IAM Policy With CloudFront Config

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:GetBucketLocation"
            ],
            "Resource": "arn:aws:s3:::<bucketname>"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:DeleteObject",
                "s3:PutObjectAcl"
            ],
            "Resource": "arn:aws:s3:::<bucketname>/*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "cloudfront:GetDistribution",
                "cloudfront:CreateInvalidation"
            ],
            "Resource": "*"
        }
    ]
}

Background Information

If you're looking at s3deploy then you've probably already seen the aws s3 sync command - this command has a sync-strategy that is not optimised for static sites, it compares the timestamp and size of your files to decide whether to upload the file.

Because static-site generators can recreate every file (even if identical) the timestamp is updated and thus aws s3 sync will needlessly upload every single file. s3deploy on the other hand checks the etag hash to check for actual changes, and uses that instead.

Alternatives

  • go3up by Alexandru Ungur
  • s3up by Nathan Youngman (the starting-point of this project)

Stargazers over time

Stargazers over time

More Repositories

1

docuapi

Beautiful multilingual API documentation theme for Hugo
HTML
677
star
2

gr

Aka Go React: GopherJS bindings for Facebook React. NOTE: Still early and not production ready.
Go
162
star
3

hugo-starter-tailwind-basic

A basic and simple to set up Hugo with TailwindCSS starter project.
HTML
144
star
4

gallerydeluxe

Fast Hugo gallery theme/module suitable for lots of images.
JavaScript
144
star
5

debounce

A debouncer written in Go.
Go
105
star
6

godartsass

Go API backed by the native Dart Sass Embedded executable.
Go
42
star
7

killswitch

Wrap your sensitive application in a kill switch
Go
40
star
8

galleriesdeluxe

Multi gallery Hugo theme.
SCSS
39
star
9

punused

Finds unused _exported_ Go symbols in a project. Backed by gopls.
Go
38
star
10

portable-hugo-links

A test repo to test out the new Markdown Render Hooks in Hugo 0.62.0
HTML
34
star
11

gallerydeluxe_starter

Starter project for https://github.com/bep/gallerydeluxe
HTML
34
star
12

simplecobra

A simpler API for the popular Cobra CLI.
Go
34
star
13

hugotest

Test site for Hugo development and experiments, see https://temp.bep.is/hugotest/
HTML
29
star
14

gojap

This is a small library that wraps goja and adds a VM pool and compilation cache.
Go
29
star
15

logg

A Fast and Structured logging package for Go.
Go
25
star
16

gitmap

A fast way to create a map from all the filenames to info objects for a given revision of a Git repo.
Go
23
star
17

bepsays.com

Source code and content for bepsays.com
CSS
21
star
18

lazycache

Thread safe in-memory LRU cache with non-blocking cache priming on cache misses.
Go
20
star
19

golibsass

Easy to use Go bindings for LibSass.
C++
17
star
20

my-modular-site

Just a test site
HTML
16
star
21

hugo-alpine-test

Just a simple test repo to test out AlpineJS in combo with Hugo.
HTML
14
star
22

execrpc

RCP via os/exec with generic types.
Go
13
star
23

buildpkg

Builds, signs, notarizes and staples a MacOS pkg file.
Go
13
star
24

hugo-sass-test

Test repo.
HTML
12
star
25

algolia-test

HTML
12
star
26

hugo-github

Some Hugo components talking to GitHub
HTML
11
star
27

grouter

Highly Experimental React-Router Bindings for GopherJS
Go
11
star
28

html5up-to-hugo

WORK IN PROGRESS
CSS
11
star
29

workers

Set up tasks to be executed in parallel.
Go
11
star
30

hugo-jslibs

Work in Progress: A collection of JS libraries packaged and ready for use in Hugo.
JavaScript
11
star
31

golibtemplate

Template project for Go libraries.
Go
10
star
32

dockerfiles

Dockerfile
9
star
33

grcomponents

Some usable components for Go React, see https://github.com/bep/gr
Go
9
star
34

hugo-bulma-hero

Work In progress
HTML
8
star
35

macosnotarylib

Notarize files using Apple's Notary API.
Go
8
star
36

go-tocss

A simple to use Go API for LibSass. Uses CGO.
Go
8
star
37

speedwriter

Speedwriter -- write like the wind!
Go
8
star
38

tmc

Provides basic roundtrip JSON etc. encoding/decoding of a map[string]any with custom type adapters.
Go
8
star
39

imagemeta

Go library for reading EXIF, IPTC and XMP image meta data from JPEG, TIFF, PNG, and WebP files.
Go
6
star
40

gomaintemplate

Just a simple main() program template.
Go
6
star
41

overlayfs

A composite Afero filesystem.
Go
6
star
42

hugo-testing-tailwindcss-v4

A test/demo repo.
CSS
6
star
43

twittercard-proxy

Create pretty Twitter Cards for your GitHub releases etc.
Go
5
star
44

hugo-mod-misc

Some useful Hugo Modules.
HTML
5
star
45

gotfmt

Work In Progress.
Go
5
star
46

bep

Software Developer and Saxophonist from Norway.
4
star
47

hugo-starter-tailwindjit-basic

Work in progress.
JavaScript
4
star
48

mammon

Mammon is a hacking scene app for movie and television producers (work in progress)
Go
4
star
49

poormanscdn

poormanscdn is a caching proxy to Amazon S3 built using Go
Go
4
star
50

s3tlsproxy

WORK IN PROGRESS: Amazon S3 cache with auto TLS and virtual hosts support
Go
3
star
51

ewis

Play with chords on your EWI (electronic wind instrument)
JavaScript
3
star
52

gorder

Opinionated Go source code reorganizer.
Go
3
star
53

gobench

Benchmark runner with pprof support.
Go
3
star
54

npmgoproxy

This highly experimental and very much work in progress.
Go
3
star
55

hugo-gulp

Gulp tasks or my Hugo sites. May be of limited use to others.
JavaScript
3
star
56

clocks

A Golang clock that allows you to set the start time.
Go
3
star
57

netlify-cypress-test

Just a minimal repo to set up a Cypress integration test running in a GitHub Action after a successful Netlify preview build.
JavaScript
3
star
58

create-a-million-pages

Just a generator to create some BIG Hugo test sites
Go
3
star
59

googlephotosalbum

Work in progress. A Hugo Module to infinite scroll a Google Photos Album.
HTML
3
star
60

gosandbox

Sandbox for Golang experiments and demos.
Go
3
star
61

hugo-starter-bootstrap-basic

A basic Hugo starter project for Bootstrap v5.
HTML
2
star
62

editorial

WORK IN PROGRSS Editorial theme for Hugo
CSS
2
star
63

alfn

Aggregated Latest Filtered News
Go
2
star
64

hugo-benchmark

Builds a set of random, but real Hugo sites and prints some stats.
Go
2
star
65

htmldiffer

Work in progress (experimental)
Go
2
star
66

hugo-dartsass-testrepo

Just a test repo to test Hugo/Netlify/DartSass integration.
HTML
2
star
67

helloworld

Just a test rpo.
Go
2
star
68

githubtempl

Generate a templated file (e.g. README.md) from GitHub user data
Go
2
star
69

refliter

Just some generics testing.
Go
2
star
70

semverpair

A specification and some utility functions for a very simple encoding scheme that combines two semver versions.
Go
2
star
71

staticbattery.com

Source for staticbattery.com
HTML
2
star
72

fetch-npm-package

Just a small utility that can be used to fetch a given version of a NPM package.
Go
2
star
73

gallerydeluxe-demo-images-listed-in-a-file

HTML
2
star
74

firstupdotenv

Loads env from the first firstup.env it finds.
Go
2
star
75

deleteme1

HTML
1
star
76

forsale

Just some promotional pages/images for items for sale.
JavaScript
1
star
77

hugotestmods

Just for testing.
HTML
1
star
78

sandbox

Sandbox for testing out different things.
Groovy
1
star
79

wiki

A wiki with notes and test stuff.
1
star
80

netlify-lighthouse-test

Just a simple test repo to test Lighthouse with Netlify.
JavaScript
1
star
81

powermeter

Work In Progess: A process wrapper that measures power usage. MacOS only.
1
star
82

hugo-schema

Work in progress.
Go
1
star
83

go120winpathregression

Go
1
star
84

hugo-js-decorator

1
star
85

githubactionstest

Just a test repo to test out some GitHub Action issues.
1
star
86

hugo-reactive-poc

Some experiments/PoC in partial/reactive builds for https://github.com/spf13/hugo
1
star
87

test-esbuild-resolve-siblings

Just a test project, nothing interesting here.
Go
1
star
88

bep.is

The Code Behind bep.is
HTML
1
star
89

go-or-gopherjs

A CLI wrapper invoking go or gopherjs based on GOARCH == "js".
Go
1
star
90

triebytesmapper

Work in progress.
Go
1
star
91

htmlfmt

Work in progress. HTML formatter.
Go
1
star
92

mod-sub-sub

Just a test repo.
1
star
93

helpers

An utils package with a less burdened name.
Go
1
star
94

mclib

A simple library to make it possible to run Mkcert's main method.
Go
1
star
95

hugotemplate

An opinionated and basic template for a new Hugo project.
HTML
1
star