S3 website deployment tool
Project description
This is a deployment tool for uploading static websites to S3. If CloudFront is used for hosting the website, the uploaded files can be automatically invalidated in the CloudFront distribution. A prefix tree is used to minimize the number of invalidations since only a limited number of free invalidations are available per month.
The configuration is stored in a YAML file like this:
site: _site
s3_bucket: example.com
cloudfront_distribution_id: XXXXXXXXXXX
cache_rules:
- match: "/assets/*"
maxage: 30 days
- match: "/css/*"
maxage: 30 days
- match: "*"
maxage: 1 hour
The site is the directory of the static website relative to the location of the configuration file. For example, Jekyll will generate the static site in the _site directory as specified above. If you save the configuration file as .s3_website.yaml you can simply run s3-deploy-website from the same directory:
$ cd jekyll-site/
$ ls .s3_website.yaml
.s3_website.yaml
$ s3-deploy-website
Credentials
AWS credentials can be provided through the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
$ export AWS_ACCESS_KEY_ID=XXXXXX
$ export AWS_SECTER_ACCESS_KEY=XXXXXX
$ s3-deploy-website
They can also be provided through the various configuration files that boto reads.
Configuration file
- site
The directory of the static content to be uploaded (relative to the location of the configuration file (e.g. _site for Jekyll sites).
- s3_bucket
The name of the S3 bucket to upload the files to. You have to allow the actions s3:GetObject, s3:PutObject, s3:DeleteObject and s3:ListBucket on the bucket and the keys e.g. arn:aws:s3:::example.com and arn:aws:s3:::example.com/*.
- cloudfront_distribution_id
The CloudFront distribution to invalidate after uploading new files. Only files that were changed will be invalidated. You have to allow the action cloudfront:CreateInvalidation.
- cache_rules
A list of rules to determine the cache configuration of the uploaded files. The match key specifies a pattern that the rule applies to. Only the first rule to match a given key will be used. The maxage key specifies the time to cache the file. The value should be either a number of seconds or a string like 30 days, 5 minutes, 30 seconds, etc.
Similar software
The configuration in .s3_website.yaml was inspired by s3_website although the options supported by s3_website are slightly different.
Licence
MIT.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for s3_deploy_website-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fda2cac40386ee56a149a994b315ec3373a8652d8f0f216d644ca7ad57473f3b |
|
MD5 | 1f90f619e0524ec13f81e2ea9ce533f5 |
|
BLAKE2b-256 | 7dd2595e67305639580e96908f9fb5ffd9aefa528f20c0b51e3bf2d11939a207 |