Rapidly deploy a static website to the Amazon Web Services (AWS) cloud.
This is a Cookiecutter template. Use Cookiecutter to generate a new project for static websites in the cloud using this template.
The project generated by this template uses a CloudFormation script to quickly create:
- 2 S3 Buckets:
- a Root Bucket for storing the website
- a Log Bucket for storing logs from the Root Bucket and CloudFront
- 1 CloudFront Distribution (AWS' Content-Distribution Network [CDN]) with TLS
- 1 Hosted Zone (a DNS zone)
- 2 DNS A Records for both domain.tld and www.domain.tld
The tools required to generate a project using this template:
- Python 2.7 or 3.3+
- pip
- virtualenvwrapper (recommended but technically optional)
- Cookiecutter
Tools required to obtain a security certificate:
The tools required to use the project generated by this template.
All other requirements (including AWS
CLI) are in the template's
requirements.txt
file.
-
Sign up for AWS
-
Generate the project using Cookiecutter, virtualenvwrapper, and this template
$ mkvirtualenv PROJECT_SLUG # replace PROJECT_SLUG $ pip install cookiecutter $ cd $PROJECT_HOME # PROJECT_HOME is used by virtualenvwrapper, and must be defined in .bashrc $ cookiecutter gh:jambonsw/cookiecutter-static-site $ cd PROJECT_SLUG # replace with the value you specified when prompted by cookiecutter $ setvirtualenvproject # or: setvirtualenvproject $VIRTUAL_ENV $(builtin pwd) $ pip install -r requirements.txt $ mv env.sh $WORKON_HOME/$(basename $VIRTUAL_ENV)/bin/postactivate $ mv unenv.sh $WORKON_HOME/$(basename $VIRTUAL_ENV)/bin/postdeactivate
Example prompt input:
project_name [My Static Website]: JamBon Software project_slug [jambon-software]: jambonsw domain_name [example.com]: jambonsw.com aws_access_key_id [XXXXXXXXXXXXXXXXXXXX]: aws_secret_access_key [XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX]:
-
Obtain a TLS Certificate
$ cd certificates $ openssl genrsa 2048 > private-key.pem $ openssl req -new -key private-key.pem -out csr.pem $ # Buy Cert; upload CSR $ # for any files received: $ openssl x509 -in jambonsw_com.crt -outform pem -out jambonsw_com_cert.pem $ # 3 files expected: certificate, certificate chain, private key $ # for example, this might be: jambonsw_com_cert.pem jambonsw_com_ca_chain.pem private-key.pem
-
Activate Envionment
$ workon PROJECT_SLUG # replace PROJECT_SLUG
-
Upload the TLS Certificate to AWS
$ make upload-cert
-
Generate the CloudFormation parameters file.
$ ./generate-params.sh
-
Create CloudFormation Stack
$ make create-stack
-
Go Make Tea. The stack will take a bit. (Only the AWS web console will be able to tell you when the stack is done.)
-
Point your domain at the nameservers. Use code below to get your nameservers.
$ make dns
-
Upload your content
$ make
Your site is now in the cloud!
If you add content to the content
directory, simply use make
to
update your site.
If you change the cloudformation scripts (you can!) you may use make stack
to update the stack.
$ make delete-stack
Voila!