Allows you to upload static files to S3 buckets.
- Uploads are fast (only changed files are sent).
- Old files (or files that no longer match the set of patterns) are deleted. Easily remove accidental uploads by simply changing the configuration and redeploying.
- Configuration uses Ant Glob syntax. Easy to understand and update.
Install via npm:
npm install -g s3-upload
Log into your AWS S3 console and create a new bucket for your site.
Bucket names must conform with DNS requirements:
- Should not contain uppercase characters
- Should not contain underscores
- Should be between 3 and 63 characters long
- Should not end with a dash
- Cannot contain two, adjacent periods
- Cannot contain dashes next to periods (e.g., "my-.bucket.com" and "my.-bucket" are invalid)
Once the bucket is created, select it and choose
Properties > Static Website Hosting.
Choose proper values for the
Index Document and
Error Document fields (i.e. index.html and 404.html).
The Error Document path is always relative to the root of the site. All errors are redirected to http://my.aws.site.com/404.html.
Static sites hosted on S3 do not support private files (password protection, etc). You must make all files publicly accessible. From your buckets
Properties page, choose
Permissions > Edit/Add bucket policy. Copy and past the policy below (replace YOUR-BUCKET-NAME for the bucketName you created previously)
Have AWS create a new key pair for the user and copy the contents into a
aws-credentials.json file in the root directory of your project. You should add this file to
.gitignore (or similar) so that credentials are not checked into version control.
From the AWS IAM Users Console select the newly created user, then the
Permissions Tab, then click the
Attach User Policy button. Paste in the following (substituting BUCKET-NAME as appropriate).
Create a file called
aws-upload.conf.js in the root directory of your project and copy and paste in the code below. Modify
bucketName and the
patterns array as appropriate for your project. All patterns are evaluated with the current directory as root, and the bucket directory structure will mirror the local one.
s3-upload from the same directory as your config file, and the upload will happen.