Skip to content

Cookiecutter template for quickly deploying static websites to Amazon Web Services (AWS).

License

Notifications You must be signed in to change notification settings

jambonsw/cookiecutter-static-site

Repository files navigation

Cookiecutter Static Site Deployment

Rapidly deploy a static website to the Amazon Web Services (AWS) cloud.

Full Walkthrough here!

What does this do?

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)

Requirements

The tools required to generate a project using this template:

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.

Generating a Project with this Template

  1. Sign up for AWS

  2. 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]: 
  3. 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

Deploy Static Website

  1. Activate Envionment

    $ workon PROJECT_SLUG  # replace PROJECT_SLUG
  2. Upload the TLS Certificate to AWS

    $ make upload-cert
  3. Generate the CloudFormation parameters file.

    $ ./generate-params.sh
  4. Create CloudFormation Stack

    $ make create-stack
  5. 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.)

  6. Point your domain at the nameservers. Use code below to get your nameservers.

    $ make dns
  7. Upload your content

    $ make

Your site is now in the cloud!

Update your Site

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.

Deleting the Stack

$ make delete-stack

Voila!

About

Cookiecutter template for quickly deploying static websites to Amazon Web Services (AWS).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published