|
1 | | - |
| 1 | +# s3www: Serve Static Files from S3-Compatible Storage |
2 | 2 |
|
3 | | -Serve static files from any S3 compatible object storage endpoints. |
4 | | - |
5 | | -> Simplifies and secure [AWS S3 Static Website Hosting](https://docs.aws.amazon.com/AmazonS3/latest/userguide/WebsiteHosting.html) by keeping your bucket private, secure, run-anywhere you like and with Automatic TLS based on Let's Encrypt. |
| 3 | +s3www is a lightweight, open-source tool to serve static files from any S3-compatible object storage service, such as AWS S3, MinIO, or DigitalOcean Spaces. It supports HTTPS with Let's Encrypt for secure hosting and is ideal for hosting static websites, single-page applications (SPAs), or file servers. |
6 | 4 |
|
7 | 5 | ## Features |
8 | | -- Automatic credentials rotation when deployed on AWS EC2, ECS or EKS services for your AWS S3 buckets - yay! 🔒😍 |
9 | | -- Automatic certs renewal for your DOMAIN along with OCSP stapling, full suite of ACME features, HTTP->HTTPS redirection (all thanks to [certmagic](https://github.com/caddyserver/certmagic)). |
10 | 6 |
|
11 | | -## Install |
12 | | -Released binaries are available [here](https://github.com/harshavardhana/s3www/releases), or you can compile yourself from source. |
| 7 | +- **S3 Compatibility**: Works with any S3-compatible storage provider. |
| 8 | +- **HTTPS Support**: Automatic TLS certificates via Let's Encrypt. |
| 9 | +- **Lightweight**: Built in Go for performance and minimal resource usage. |
| 10 | +- **SPA Support**: Configurable single-page application routing. |
| 11 | +- **Customizable**: Supports custom error pages and CORS configuration. |
| 12 | +- **Cross-Platform**: Runs on Linux, macOS, FreeBSD, and more. |
13 | 13 |
|
14 | | -> NOTE: minimum Go version needed is v1.18 |
| 14 | +## Prerequisites |
15 | 15 |
|
16 | | -``` |
17 | | -go install github.com/harshavardhana/s3www@latest |
| 16 | +- An S3-compatible storage bucket with static files (e.g., `index.html`). |
| 17 | +- S3 credentials with `s3:GetObject` and `s3:ListBucket` permissions. |
| 18 | +- Go 1.21+ (for building from source) or Docker/Podman (for containerized deployment). |
| 19 | +- Network access to your S3 endpoint and port 8080 (or your chosen port). |
| 20 | + |
| 21 | +### Required S3 Permissions |
| 22 | + |
| 23 | +```json |
| 24 | +{ |
| 25 | + "Version": "2012-10-17", |
| 26 | + "Statement": [ |
| 27 | + { |
| 28 | + "Sid": "AllowGetObject", |
| 29 | + "Effect": "Allow", |
| 30 | + "Action": "s3:GetObject", |
| 31 | + "Resource": "arn:aws:s3:::<Bucket Name>/*" |
| 32 | + }, |
| 33 | + { |
| 34 | + "Sid": "AllowListBucket", |
| 35 | + "Effect": "Allow", |
| 36 | + "Action": "s3:ListBucket", |
| 37 | + "Resource": "arn:aws:s3:::<Bucket Name>" |
| 38 | + } |
| 39 | + ] |
| 40 | +} |
18 | 41 | ``` |
19 | 42 |
|
20 | | -## Binary |
21 | | -Make sure you have `index.html` under `mysite` |
| 43 | +## Installation |
| 44 | + |
| 45 | +### Option 1: Download Prebuilt Binaries |
| 46 | + |
| 47 | +1. Visit the [Releases page](https://github.com/harshavardhana/s3www/releases) and download the binary for your platform (e.g., `s3www_0.9.0_linux_amd64.tar.gz`). |
| 48 | +2. Extract the archive: |
| 49 | + ```bash |
| 50 | + tar -xzf s3www_0.9.0_linux_amd64.tar.gz |
| 51 | + ``` |
| 52 | +3. Move the binary to a directory in your PATH: |
| 53 | + ```bash |
| 54 | + sudo mv s3www /usr/local/bin/ |
| 55 | + ``` |
| 56 | + |
| 57 | +### Option 2: Run with Docker |
| 58 | + |
| 59 | +```bash |
| 60 | +docker run --rm -p 8080:8080 y4m4/s3www:latest \ |
| 61 | + -endpoint "https://s3.amazonaws.com" \ |
| 62 | + -accessKey "accessKey" \ |
| 63 | + -secretKey "secretKey" \ |
| 64 | + -bucket "mysite" \ |
| 65 | + -address "0.0.0.0:8080" |
22 | 66 | ``` |
23 | | -s3www -endpoint "https://s3.amazonaws.com" -accessKey "accessKey" \ |
24 | | - -secretKey "secretKey" -bucket "mysite" |
25 | 67 |
|
26 | | -s3www: Started listening on http://127.0.0.1:8080 |
| 68 | +### Option 3: Build from Source |
| 69 | + |
| 70 | +1. Clone the repository: |
| 71 | + ```bash |
| 72 | + git clone https://github.com/harshavardhana/s3www.git |
| 73 | + cd s3www |
| 74 | + ``` |
| 75 | +2. Build the binary: |
| 76 | + ```bash |
| 77 | + go build |
| 78 | + ``` |
| 79 | +3. Move the binary to a directory in your PATH: |
| 80 | + ```bash |
| 81 | + sudo mv s3www /usr/local/bin/ |
| 82 | + ``` |
| 83 | + |
| 84 | +## Usage |
| 85 | + |
| 86 | +1. **Basic Command**: |
| 87 | + Serve files from an S3 bucket over HTTP: |
| 88 | + ```bash |
| 89 | + s3www -endpoint "https://s3.amazonaws.com" \ |
| 90 | + -accessKey "accessKey" \ |
| 91 | + -secretKey "secretKey" \ |
| 92 | + -bucket "mysite" |
| 93 | + ``` |
| 94 | + Output: |
| 95 | + ``` |
| 96 | + s3www: Started listening on http://127.0.0.1:8080 |
| 97 | + ``` |
| 98 | + Open `http://127.0.0.1:8080` in your browser to verify. |
| 99 | + |
| 100 | +2. **With Let's Encrypt**: |
| 101 | + Serve over HTTPS with automatic TLS certificates: |
| 102 | + ```bash |
| 103 | + s3www -endpoint "https://s3.amazonaws.com" \ |
| 104 | + -accessKey "accessKey" \ |
| 105 | + -secretKey "secretKey" \ |
| 106 | + -bucket "mysite" \ |
| 107 | + -lets-encrypt \ |
| 108 | + -address "example.com" |
| 109 | + ``` |
| 110 | + Output: |
| 111 | + ``` |
| 112 | + s3www: Started listening on https://example.com |
| 113 | + ``` |
| 114 | + Open `https://example.com` in your browser. |
| 115 | + |
| 116 | +3. **Single-Page Application (SPA)**: |
| 117 | + Serve an SPA by specifying a fallback file: |
| 118 | + ```bash |
| 119 | + s3www -endpoint "https://s3.amazonaws.com" \ |
| 120 | + -accessKey "accessKey" \ |
| 121 | + -secretKey "secretKey" \ |
| 122 | + -bucket "mysite" \ |
| 123 | + -spa "index.html" |
| 124 | + ``` |
| 125 | + |
| 126 | +## Configuration |
| 127 | + |
| 128 | +You can configure s3www via command-line flags or environment variables: |
| 129 | + |
| 130 | +| Flag | Environment Variable | Description | Default | |
| 131 | +|------------------|------------------------|------------------------------------------|----------------------| |
| 132 | +| `-endpoint` | `S3WWW_ENDPOINT` | S3 endpoint URL | | |
| 133 | +| `-accessKey` | `S3WWW_ACCESS_KEY` | S3 access key | | |
| 134 | +| `-secretKey` | `S3WWW_SECRET_KEY` | S3 secret key | | |
| 135 | +| `-bucket` | `S3WWW_BUCKET` | S3 bucket name | | |
| 136 | +| `-address` | `S3WWW_ADDRESS` | Host and port to listen on | `127.0.0.1:8080` | |
| 137 | +| `-lets-encrypt` | | Enable Let's Encrypt TLS | `false` | |
| 138 | +| `-spa` | `S3WWW_SPA` | Fallback file for SPA routing | | |
| 139 | +| `-tls-cert` | `S3WWW_TLS_CERT` | Path to TLS certificate file | | |
| 140 | +| `-tls-key` | `S3WWW_TLS_KEY` | Path to TLS key file | | |
| 141 | + |
| 142 | +Example using environment variables: |
| 143 | +```bash |
| 144 | +export S3WWW_ENDPOINT="https://s3.amazonaws.com" |
| 145 | +export S3WWW_ACCESS_KEY="accessKey" |
| 146 | +export S3WWW_SECRET_KEY="secretKey" |
| 147 | +export S3WWW_BUCKET="mysite" |
| 148 | +export S3WWW_ADDRESS="0.0.0.0:8080" |
| 149 | +s3www |
27 | 150 | ``` |
28 | 151 |
|
29 | | -Point your web browser to http://127.0.0.1:8080 ensure your `s3www` is serving your `index.html` successfully. |
| 152 | +## Use Cases |
30 | 153 |
|
31 | | -## Container |
32 | | -Make sure you have `index.html` under `mysite` |
| 154 | +- **Static Website Hosting**: Serve HTML, CSS, and JavaScript files for blogs, portfolios, or documentation. |
| 155 | +- **Single-Page Applications**: Host React, Vue, or Angular apps with proper routing. |
| 156 | +- **File Sharing**: Share files securely from an S3 bucket over HTTPS. |
| 157 | +- **Development Testing**: Quickly test static assets from S3 during development. |
33 | 158 |
|
34 | | -``` |
35 | | -podman run --rm -p 8080:8080 y4m4/s3www:latest \ |
36 | | - -endpoint "https://s3.amazonaws.com" \ |
37 | | - -accessKey "accessKey" \ |
38 | | - -secretKey "secretKey" \ |
39 | | - -bucket "mysite" \ |
40 | | - -address "0.0.0.0:8080" |
41 | | -
|
42 | | -s3www: Started listening on http://0.0.0.0:8080 |
43 | | -``` |
| 159 | +## Troubleshooting |
44 | 160 |
|
45 | | -Point your web browser to http://127.0.0.1:8080 ensure your `s3www` is serving your `index.html` successfully. |
| 161 | +- **404 Errors**: Ensure your bucket contains an `index.html` file or specify a custom SPA file with `-spa`. |
| 162 | +- **Permission Denied**: Verify your S3 credentials have `s3:GetObject` and `s3:ListBucket` permissions. |
| 163 | +- **Let's Encrypt Issues**: Ensure your domain is publicly accessible and port 80 is open for certificate issuance. |
| 164 | +- **Connection Errors**: Check the S3 endpoint URL and your network connectivity. |
46 | 165 |
|
47 | | -## Auto TLS |
48 | | -Make sure you have `index.html` under `mysite` |
49 | | -``` |
50 | | -s3www -endpoint "https://s3.amazonaws.com" -accessKey "accessKey" \ |
51 | | - -secretKey "secretKey" -bucket "mysite" \ |
52 | | - -lets-encrypt -address "example.com" |
| 166 | +## Contributing |
53 | 167 |
|
54 | | -s3www: Started listening on https://example.com |
55 | | -``` |
| 168 | +We welcome contributions! To get started: |
56 | 169 |
|
57 | | -Point your web browser to https://example.com ensure your `s3www` is serving your `index.html` successfully. |
| 170 | +1. Fork the repository. |
| 171 | +2. Create a feature branch (`git checkout -b feature-name`). |
| 172 | +3. Commit your changes (`git commit -m "Add feature"`). |
| 173 | +4. Push to the branch (`git push origin feature-name`). |
| 174 | +5. Open a pull request. |
58 | 175 |
|
59 | | -## Permissions |
| 176 | +Please read the [CONTRIBUTING.md](CONTRIBUTING.md) for details. |
60 | 177 |
|
61 | | -### AWS IAM Policy |
62 | | -s3www requires access to view and list all files in the bucket. |
| 178 | +## License |
63 | 179 |
|
64 | | -``` |
65 | | -{ |
66 | | - "Version": "2012-10-17", |
67 | | - "Statement": [ |
68 | | - { |
69 | | - "Sid": "", |
70 | | - "Effect": "Allow", |
71 | | - "Action": "s3:GetObject", |
72 | | - "Resource": "arn:aws:s3:::<Bucket Name>/*" |
73 | | - }, |
74 | | - { |
75 | | - "Sid": "", |
76 | | - "Effect": "Allow", |
77 | | - "Action": "s3:ListBucket", |
78 | | - "Resource": "arn:aws:s3:::<Bucket Name>" |
79 | | - } |
80 | | - ] |
81 | | -} |
82 | | -``` |
83 | | -# License |
84 | | -This project is distributed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0), see [LICENSE](./LICENSE) for more information. |
| 180 | +This project is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for more information. |
0 commit comments