Authenticate S3 using Lambda@Edge
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
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
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
Following are the objects created in AWS in our approach:
Assuming that AWS account is already created
Since we use Google authorization mechanism
serverless.yml
and replace <static-site-bucket-name>
with the name of the bucket you would like to create and use as static websitemain.js
and replace GOOGLE_CLIENT_ID
string with Client ID of oauth client configured for your GCP projectnpm install
assuming that you have npm
installed on your machinesls deploy
assuming that you have serverless
installed on your machine
Usually it takes 15-20 minutes for AWS Cloudfront to copy files to edge locationshtml_templates/main.html
and replace clientId
value with oauth client idindex.html
as an entry pointmain.html
, index.html
and all other required files into AWS S3 bucket defined in serverless.yml
Further, serverless-finch
plugin could be used to automate copying site contents to S3Navigate to AWS Cloudfront origin create after sls deploy
completion.
Then edit the origin object and set following parameters:
To secure multiple pages using google authentication, go to Cloudfront distribution -> Edit settings
If you want to attach a custom domain name to your Cloudfront distribution, you need to:
Alternate Domain Names (CNAMEs)
list