{"id":18977303,"url":"https://github.com/mikhailms/aws-2tier-lambda-api","last_synced_at":"2026-01-27T19:31:29.875Z","repository":{"id":207614747,"uuid":"715770837","full_name":"MikhailMS/aws-2tier-lambda-api","owner":"MikhailMS","description":"Attempt to build 2 Tier application that utilises API Gateway","archived":false,"fork":false,"pushed_at":"2023-12-10T14:57:26.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-02T14:55:48.978Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HCL","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/MikhailMS.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":"2023-11-07T19:54:29.000Z","updated_at":"2023-11-16T16:26:41.000Z","dependencies_parsed_at":"2023-11-19T18:39:20.977Z","dependency_job_id":"dfc1772a-391e-4787-a664-d9c4d22a0c9d","html_url":"https://github.com/MikhailMS/aws-2tier-lambda-api","commit_stats":null,"previous_names":["mikhailms/aws-2tier-lambda-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MikhailMS/aws-2tier-lambda-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MikhailMS%2Faws-2tier-lambda-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MikhailMS%2Faws-2tier-lambda-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MikhailMS%2Faws-2tier-lambda-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MikhailMS%2Faws-2tier-lambda-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MikhailMS","download_url":"https://codeload.github.com/MikhailMS/aws-2tier-lambda-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MikhailMS%2Faws-2tier-lambda-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28819420,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T18:44:20.126Z","status":"ssl_error","status_checked_at":"2026-01-27T18:44:09.161Z","response_time":168,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-08T15:28:29.872Z","updated_at":"2026-01-27T19:31:29.842Z","avatar_url":"https://github.com/MikhailMS.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AWS 2 Tier application with API Gateway\n\nThis project is part of one big project where I research how to build infrastructure in AWS for 2-tier application (and application as well, of course) :\n1. Terraform (this project) contains all the terraform code to deploy required infra \u0026 application code\n2. [Simple Web GUI](https://github.com/MikhailMS/aws-simple-web-gui) contains code for simple Web GUI to bridge the gap between user and Lambda functions\n3. [Lambda functions](https://github.com/MikhailMS/aws-lambda-functions) contain code for 3 Lambda functions that replicate simple backend functions\n    1. `return_ip`         - returns IP address of the Lambda function\n    2. `fetch_go_versions` - returns JSON with recent 5 Go versions\n    3. `custom_auth`       - custom Lambda authorizer (only supports payload format `version 1.0`) that controls access to functions `1 \u0026 2` when calling via API Gateway\n    4. `custom_auth_v2`    - custom Lambda authorizer (only supports payload format `version 2.0`) that controls access to functions `1 \u0026 2` when calling via API Gateway\n\nSimple representation of the thing that gets built with this Terraform project (application is also getting deployed as part of this Terraform project):\n```\n                   ------------------------------------|--------------------------------\n                   |                MAIN VPC           |            Public space       |\n                   |                                   |                               |\n                   |                                   |            \u003c--\u003e  Auth Lambda  |\n              -----------                       ---------------     |                  |\nClient ---\u003e   | Route 53 |   --\u003e Web GUI --\u003e    | API Gateway | --\u003e  --\u003e  Lambda 1     |\n              ------------                      ---------------     |                  |\n                   |                                   |             --\u003e  Lambda 2     |\n                   |                                   |                               |\n                   |                                   |                               |\n                   ------------------------------------|--------------------------------\n```\n\nAuth(authentication) Lambda is required so we can delegate authentication to API Gateway (albeit there are other ways to do this) instead of doing it in Lambda 1/2\n\n\n## Usage\n1. Git clone this project\n2. Ensure you have authentication credentials set for Terraform; account should have permissions to create:\n    1. Networks: VPC, Subnets, LB etc\n    2. Applications: Auto Scaling groups, Launch templates etc\n    3. API Gateway\n    4. AWS Lambda Functions\n3. Ensure you have following items ready prior to launching Terraform:\n    1. S3 buckets to host Terraform state files for\n        1. Networking  - sets up network that would be used by API Gateway, Lambdas \u0026 Web Tier;           set in `network/backend-config.tfvars`\n        2. Lambdas     - spins up Lambda Functions that are to be called from Web Tier (via API Gateway); set in `lambdas/backend-config.tfvars`\n        3. API Gateway - sets up API Gateway: linkage between Web-Tier and Lambdas + authentication;      set in `api-gateway/backend-config.tfvars \u0026 api-gateway/data.tf \u003e\u003e data \u003e\u003e config \u003e\u003e bucket \u0026 region (same as what set in network)`\n        4. Web Tier    - sets up servers hosted in public subnets; accessible via Internet;               set in `web-tier/backend-config.tfvars    \u0026 web-tier/data.tf    \u003e\u003e data \u003e\u003e config \u003e\u003e bucket \u0026 region (same as what set in network \u0026 api-gateway)`\n        5. Route53     - links custom DNS (with HTTPS cert) to Web Tier LB;                               set in `route53/backend-config.tfvars     \u0026 route53/data.tf     \u003e\u003e data \u003e\u003e config \u003e\u003e bucket \u0026 region (same as what set in web-tier)`\n    2. `terraform.tfvars` file in each of the module: `api-gateway`, `lambdas`, `network`, `route53`, `web-tier` to specify:\n        1. TLS certificates (specifically ARN of those) - these would be used to ensure HTTPS connectivity is properly handled\n        2. SSH Keys - so you would be able to log onto Web Tier servers in case you need to debug/play around with those\n        3. There are other required variables, please refer to `variables.tf` in each module\n    3. `backend-config.tfvars` file in each of the module: `api-gateway`, `lambdas`, `network`, `route53`, `web-tier` to specify:\n        1. `bucket` - backend bucket\n        2. `key`    - backend key\n        3. `region` - backend region\n4. Items should be deployed in the following order:\n    1. `network`  - creates all network related resources\n    ```\n    # Required only once or whenever backend config changes\n    terraform init -backend-config=backend-config.tfvars\n\n    terraform plan  -var-file=terraform.tfvars -var-file=backend-config.tfvars\n    terraform apply -var-file=terraform.tfvars -var-file=backend-config.tfvars -auto-approve\n    ```\n    2. `lambdas` - creates all required AWS Lambda Functions\n    ```\n    # Required only once or whenever backend config changes\n    terraform init -backend-config=backend-config.tfvars\n\n    terraform plan  -var-file=terraform.tfvars -var-file=backend-config.tfvars\n    terraform apply -var-file=terraform.tfvars -var-file=backend-config.tfvars -auto-approve\n    ```\n    3. `api-gateway` - creates all AppTier (backend) related resources;   depends on the output of `network`\n    ```\n    # Required only once or whenever backend config changes\n    terraform init -backend-config=backend-config.tfvars\n\n    terraform plan  -var-file=terraform.tfvars -var-file=backend-config.tfvars\n    terraform apply -var-file=terraform.tfvars -var-file=backend-config.tfvars -auto-approve\n    ```\n    4. `web-tier` - creates all WebTier (front end) related resources; depends on the output of `network` \u0026 `app-tier`\n    ```\n    # Required only once or whenever backend config changes\n    terraform init -backend-config=backend-config.tfvars\n\n    terraform plan  -var-file=terraform.tfvars -var-file=backend-config.tfvars\n    terraform apply -var-file=terraform.tfvars -var-file=backend-config.tfvars -auto-approve\n    ```\n    5. `route53` - links custom DNS (with HTTPS cert) to Web Tier LB; depends on the output of `web-tier`\n    ```\n    # Required only once or whenever backend config changes\n    terraform init -backend-config=backend-config.tfvars\n\n    terraform plan  -var-file=terraform.tfvars -var-file=backend-config.tfvars\n    terraform apply -var-file=terraform.tfvars -var-file=backend-config.tfvars -auto-approve\n    ```\n\n\n## Authentication\nBy default, AWS provider expects `default` AWS Config \u0026 Crendentials (this could be changed)\n```\n# from main.tf\nprovider \"aws\" {\n  region  = \"eu-west-2\"\n  profile = \"default\"\n}\n\n# cat ~/.aws/config\n[default]\nregion = eu-west-2\noutput = json\n\n# cat ~/.aws/credentials\n[default]\naws_access_key_id     = \u003cACCESS_KEY_ID\u003e\naws_secret_access_key = \u003cSECRET_ACCESS_KEY\u003e\n```\n\n\n## Remove infrastructure\n1. At the moment it is not nicely implemented, so the only way to remove created infrastructure, is to\n```\n1. Comment out everything in main.tf \u0026 outputs.tf(if exists) for each deployed module\n2. Run `terraform apply` in the following order (effectively in the reverse)\n    1. Route53\n    2. Web Tier\n    3. API Gateway\n    4. Lambdas\n    5. Networks\n```\n\n\n## Notes:\n1. Tested with **Terraform v1.4.0**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikhailms%2Faws-2tier-lambda-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikhailms%2Faws-2tier-lambda-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikhailms%2Faws-2tier-lambda-api/lists"}