Git Product home page Git Product logo

serverless-static-website's Introduction

Serverless static website

This is a terraform script to setup a serverless infrastructure for static website hosting on aws using S3, CloudFront, Route53 and Certificate Manager.

Setup

First terraform must be installed:

# unix
sudo apt-get install unzip
wget https://releases.hashicorp.com/terraform/0.11.10/terraform_0.11.10_linux_amd64.zip
unzip terraform_0.11.10_linux_amd64.zip
sudo mv terraform /usr/local/bin/

# macOS
brew install terraform

AWS account

Create an aws account and get the access and security key for the user. Then add the keys to the environment variables.

export TF_VAR_access_key="<your-access-key>"
export TF_VAR_secret_key="<your-secret-key>"

To have the variables always available, add the two lines to the ~/.bashrc file and run source ~/.bashrc to reload the file.

Next set the preferred aws region (default is eu-central-1)and the domain without a protocol and without www. in the variables.tf file.

E-Mail

The domain verification for the SSL certificate is done via email. Make sure that you have access to at least one of the following e-mail accounts:

administrator@<your-domain>
hostmaster@<your-domain>
postmaster@<your-domain>
webmaster@<your-domain>
admin@<your-domain>

Usage

After completing the setup section check the terraform script:

terraform plan

The output shows which actions terraform will perform. If this is ok, start the creation for the infrastructure.

terraform apply

While terraform creates all components, amazon will send an e-mail for the domain verification. Check your e-mails and verify the domain, otherwise terraform will run into a timeout after a few minutes.

Rework

After terraform is complete there are a few manual steps.

Setup nameserver

Login into the aws account, go to Route53 service and view the hosting zones. Select the new domain and find the nameserver from aws. Go to your domain provider and change the nameserver. This can take up to 48 hour until the new nameserver is set.

Upload website

Go to the aws S3 service and select the bucket with the domainname. Upload the index.html and all required files for the website.

Verification

If the nameserver change is completed the website is available for the given domain, with and without www prefix. The website also supports IPv4 and IPv6 and uses force redirect from http to https.

Check IPv6: http://ipv6-test.com/validate.php

Check SSL setting: https://www.ssllabs.com/ssltest/

serverless-static-website's People

Contributors

marvincaspar avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.