{"id":18708632,"url":"https://github.com/va1da5/aws-protected-static-site","last_synced_at":"2025-11-09T10:30:25.070Z","repository":{"id":106644548,"uuid":"437558504","full_name":"va1da5/aws-protected-static-site","owner":"va1da5","description":"An example AWS deployment configuration for a static site protected by basic authentication.","archived":false,"fork":false,"pushed_at":"2021-12-17T17:24:46.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-28T07:31:41.085Z","etag":null,"topics":["aws","aws-lambda","aws-lambda-edge","cloudfront","static-site","terraform"],"latest_commit_sha":null,"homepage":"","language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/va1da5.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-12T13:50:36.000Z","updated_at":"2021-12-17T17:24:49.000Z","dependencies_parsed_at":"2024-01-11T11:03:25.716Z","dependency_job_id":null,"html_url":"https://github.com/va1da5/aws-protected-static-site","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/va1da5%2Faws-protected-static-site","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/va1da5%2Faws-protected-static-site/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/va1da5%2Faws-protected-static-site/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/va1da5%2Faws-protected-static-site/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/va1da5","download_url":"https://codeload.github.com/va1da5/aws-protected-static-site/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239571586,"owners_count":19661165,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-lambda","aws-lambda-edge","cloudfront","static-site","terraform"],"created_at":"2024-11-07T12:24:20.885Z","updated_at":"2025-11-09T10:30:25.022Z","avatar_url":"https://github.com/va1da5.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Protected Static Site in AWS S3\n\nThe repository contains a Terraform configuration for deploying a static site to [AWS S3 bucket](https://aws.amazon.com/s3/) and exposing it using [AWS CloudFront](https://aws.amazon.com/cloudfront/). The site is protected by a basic authentication using [Lambda@Edge](https://aws.amazon.com/lambda/edge/).\n\nThe static site is located in [public](public/) directory. Currently it contains an awesome CSS based visualization borrowed from [CodePen: CSS Mars Landing](https://codepen.io/mgitch/pen/pECcD). The authentication is achieved using Lambda@Edge Python function located in [aws_lambda](aws_lambda/) directory. It is a good security practice to store secrets in AWS Secrets Managers, however, this example utilizes a flat-file for credentials storage which is later bundled together with the Lambda function.\n\n\nThe [Lambda@Edge](https://aws.amazon.com/lambda/edge/) does not allow usage of environment variables, however, this functionality could be still achieved by using [python-dotenv](https://github.com/theskumar/python-dotenv) and [.env](aws_lambda/.env) file. Additionally, this provides a good example of how to bundle the Lambda function with third party dependencies.\n\n\n## Requirements:\n\n - [Terraform](https://www.terraform.io/downloads.html)\n - [AWS CLI tool](https://aws.amazon.com/cli/)\n - [Python 3.6+](https://www.python.org/downloads/)\n - [Make](https://www.gnu.org/software/make/)\n\n\n## Setup\n\n```bash\n# create local Python virtual environment\npython3 -m venv .venv\n# activate virtual environment\n. .venv/bin/activate\n# install dependencies\npip install -r local.txt\n\n# create credentials store and configure users\n./passwd.py \nWelcome to the basic password manager.\nPlease enter your username:\nvaidas\nPlease enter your password:\nPassword:\n\n\n# configure AWS CLI credentials\naws configure\n\n# set Terraform variables using .env file\nmake .env\n# or\ncp sample.env .env\n\n# load .env values to the current environment\nexport $(cat .env| xargs)\n\n# test lambda function\nmake test\n\n# deploy the site\nmake deploy\n```\n\n\n## References\n  - [Adding Authentication to Static Sites with AWS Lambda](https://douglasduhaime.com/posts/s3-lambda-auth.html)\n  - [Tutorial: Creating a simple Lambda@Edge function](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-edge-how-it-works-tutorial.html)\n  - [Lambda@Edge Design Best Practices](https://aws.amazon.com/blogs/networking-and-content-delivery/lambdaedge-design-best-practices/)\n  - [Lambda@Edge event structure](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html)\n  - [AWS Lambda context object in Python](https://docs.aws.amazon.com/lambda/latest/dg/python-context.html)\n  - [Lambda@Edge example functions](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-examples.html)\n  - [Creating AWS Lambda environment variables from AWS Secrets Manager](https://aws.amazon.com/blogs/compute/creating-aws-lambda-environmental-variables-from-aws-secrets-manager/)\n  - [Restrictions on edge functions](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/edge-functions-restrictions.html)\n  - [Redirect static websites on AWS with Lambda@Edge](https://medium.com/@robbytaylor/redirect-static-websites-on-aws-with-lambda-edge-14f2944ae02d)\n  - [Uploading Multiple files in AWS S3 from terraform](https://stackoverflow.com/questions/57456167/uploading-multiple-files-in-aws-s3-from-terraform)\n  - [Deploy Python Lambda functions with .zip file archives](https://docs.aws.amazon.com/lambda/latest/dg/python-package.html)\n  - [CodePen: CSS Mars Landing](https://codepen.io/mgitch/pen/pECcD)\n  - [How To Hash Passwords In Python](https://nitratine.net/blog/post/how-to-hash-passwords-in-python/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fva1da5%2Faws-protected-static-site","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fva1da5%2Faws-protected-static-site","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fva1da5%2Faws-protected-static-site/lists"}