s3-site-auth

Authenticate S3 using Lambda@Edge

AWS S3 based website with Google authorization

This project creates a template for a static website hosted on AWS S3 and secured with Google account authorisation This solution utilizes AWS Cloudfront + AWS Lambda@Edge solution. Please find details of the technology here

Cloudfront + Lambda@Edge Picture: AWS

We also use Serverless framework to manage deployments to AWS.

PLEASE NOTE THAT ONLY index.html IS CONSIDERED AS SENSITIVE CONTENT AND PROTECTED WITH LAMBDA@EDGE VALIDATION

Authorization rules:

Only Google users from email domain defined in main.js are allowed to browse a site secured with current solution. Feel free to adjust to your needs

Architecture

Following are the objects created in AWS in our approach:

System Requirements

  1. Node package manager
  2. NPM Serverless package
  3. AWS Credentials (using aws configure, must have access to read/write/delete)

Setup AWS account

Assuming that AWS account is already created

Setup Google project

Since we use Google authorization mechanism

Deploy new secured site container

Upload static site content

Restrict public access to index.html

Navigate to AWS Cloudfront origin create after sls deploy completion. Then edit the origin object and set following parameters:

Authenticate mutlple pages

To secure multiple pages using google authentication, go to Cloudfront distribution -> Edit settings

Defining alternative CNAME

If you want to attach a custom domain name to your Cloudfront distribution, you need to: