static-deployer aims to simplify the deploy and rollback of your static website (frontend) to AWS using a single command. It still does not create the AWS resources for you, so you need to have a previously existing S3 bucket and a CloudFront distribution configured with an origin pointing to your S3 bucket. The credentials you will use to run the static-deployer need to have List+Read+Write permissions to the specified bucket and cloudfront distribution.
pip3 install static-deployer
We recomend using aws-vault because it does not store your credentials in plaintext. But you can also use aws-cli.
After installing aws-vault, add a new profile using the following command:
aws-vault add mysite
aws-vault exec mysite -- static-deployer deploy \
--root-dir ROOT_DIR \
--patterns PATTERNS \
--bucket-name BUCKET_NAME \
--distribution-id DISTRIBUTION_ID \
--origin-name ORIGIN_NAME \
--version VERSION
--cache-maxage "1 hour"
The deploy command does the following:
- Finds all files from
ROOT_DIR
, including only those that match the patterns specified inPATTERNS
(comma separated); - Inside the bucket specified by
BUCKET_NAME
, creates a new folder/directory with the name specified inVERSION
; - Uploads all files to the folder/directory created in step 2;
- Changes the CloudFront distribution
DISTRIBUTION_ID
origin namedORIGIN_NAME
to point the folder/directory created in step 2; - Invalidates the CloudFront distribution
DISTRIBUTION_ID
cache using the pattern/*
; - Waits for the distribution changes to complete.
static-deployer rollback \
--bucket-name BUCKET_NAME \
--distribution-id DISTRIBUTION_ID \
--origin-name ORIGIN_NAME \
--version VERSION
The rollback command does the following:
- Changes the CloudFront origin
ORIGIN_NAME
to point to a previously deployed version specified byVERSION
. - Waits for the distribution changes to complete.
dry_run = "false"
[content]
root_dir = "public"
patterns = "**"
[storage]
name = "your-website-domain.com"
prefix = "{{version}}"
cache_maxage = "1 hour"
[cdn]
distribution_id = "your-cloudfront-distribution-id"
origin_name = "your-cloudfront-origin-name"
static-deployer -c config.toml deploy --version VERSION
Once you have settings in a config file, you can tell static-deployer to use the config file by using the arguments -c yourfile.toml
.
By specifying a config file, you eliminate the need of informing all parameters at every invocation. You're then required to inform only the missing parameters.
The command-line arguments override any settings you have in the config file.