{"id":16980023,"url":"https://github.com/roy-pstr/fastapi-serverless-aws-backend-service","last_synced_at":"2025-04-11T12:24:27.682Z","repository":{"id":183939193,"uuid":"582969670","full_name":"roy-pstr/fastapi-serverless-aws-backend-service","owner":"roy-pstr","description":"FastAPI python backend server with multi-stage CI/CD deployment","archived":false,"fork":false,"pushed_at":"2024-06-11T16:32:02.000Z","size":200,"stargazers_count":97,"open_issues_count":2,"forks_count":17,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-25T08:42:46.681Z","etag":null,"topics":["aws-lambda","cicd","fastapi","python","serverless-framework","template"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/roy-pstr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2022-12-28T11:32:37.000Z","updated_at":"2025-03-08T19:50:18.000Z","dependencies_parsed_at":"2024-10-28T13:22:57.127Z","dependency_job_id":"be6b7a22-2681-450b-95e3-d94e3d758387","html_url":"https://github.com/roy-pstr/fastapi-serverless-aws-backend-service","commit_stats":null,"previous_names":["roy-pstr/fastapi-serverless-aws-backend-service"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roy-pstr%2Ffastapi-serverless-aws-backend-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roy-pstr%2Ffastapi-serverless-aws-backend-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roy-pstr%2Ffastapi-serverless-aws-backend-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roy-pstr%2Ffastapi-serverless-aws-backend-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roy-pstr","download_url":"https://codeload.github.com/roy-pstr/fastapi-serverless-aws-backend-service/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248401483,"owners_count":21097328,"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-lambda","cicd","fastapi","python","serverless-framework","template"],"created_at":"2024-10-14T01:48:41.524Z","updated_at":"2025-04-11T12:24:27.659Z","avatar_url":"https://github.com/roy-pstr.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"assets/sls_lambda_fastapi.png\" data-canonical-src=\"assets/sls_lambda_fastapi.png\" width=400/\u003e\n\u003c/p\u003e\n\n# FastAPI Serverless AWS Backend Server\n\nThis project act as a template for a FastAPI server deployed on AWS Lambda for production use.\n\n\n## Features\n- Project structure template\n- FastAPI boiler plate code:\n  - Root application with versioning API (currently V1 and V2 are defined)\n  - Middleware for CORS, exceptions and logging\n  - Config module with settings loaded from your `.env` file\n  - Logs are working also in production environment (AWS Lambda)\n  - Test suite setup with TestClient\n  - Health check route and exceptions routes\n - Python code quality tools already setup both locally and as part of the CI (Pylint, Black, Isort, MyPy)\n - Dockerfile with AWS lambda base image for the FastAPI service container\n - Poetry for python environment management\n - Serverless.yml boiler plate:\n   - Lambda function for the FastAPI backend service\n   - Lambda is container-based and images are deployed to AWS ECR\n   - Defined cloud watch IAM roles and retention policy (30 days)\n   - Defined XRay IAM roles\n   - Custom domain management support in three sub-domains, one per stage.\n  - Scripts folder so you can easily run it all\n   \n## Future Features\n- boiler plate code for caching using FastAPI_Cache\n- Basic authentication and authorization with Auth0\n- Database migration support using Alembic\n\n## Prerequisites\n- An AWS account\n- The [AWS CLI](https://aws.amazon.com/cli/) installed and configured\n- [Python 3.7.2 or later](https://www.python.org/downloads/)\n- [Poetry](https://python-poetry.org/) for managing dependencies and packaging the app\n- [npm](https://www.npmjs.com/) for installing the serverless framework and plugins\n- [serverless](https://www.serverless.com/) framework for deploying the backend (just run `npm install -g serverless`)\n- [Docker](https://www.docker.com/) for building and testing the app locally\n- (Optional) An AWS Certificate of SSL/TLS certificate for a domain name in the AWS Certificate Manager ([this guide](https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains-prerequisites.html) can help)\n\n## Getting Started\n1. Clone the repository\n```\ngit clone https://github.com/larium/fastapi-serverless-aws-backend.git\n```\n\n2. Install the dependencies\n```\ncd fastapi-serverless-aws-backend\nnpm install\npoetry install\n```\n\n3. Set up local environment in `.env` file\n- Create the file: `touch .env`\n- Set the following values inside:\n```\nTBA\n```\n\n4. Set access permissions to scripts directory\n```bash\nchmod 777 ./scripts/*\n```\n\n5. Run local code analysis\n```\n./scripts/check\n```\n\n6. Run local tests\n```\n./scripts/test\n```\n\n7. Run local server\n```\n./scripts/start\n```\nTest it \u003c/br\u003e\n`curl --request GET \"https://localhost:8000\"`\n\n8. (Optional) If you want to use a custom domain for the backend, follow these steps:\n- Obtain an ARN of AWS Certificate for your domain in the AWS Certificate Manager\n- Set it on the `.env` file in `ACM_ARN`\n- In `serverless.yml` -\u003e set `customDomain.enabled: true`\n- Update the value of `baseDomain` with your base domain\n- Create the domain (this link a Route53 rule to the Certificate)\n```\n./scripts/create-domain\n```\n- Next time you will deploy the server will be exposed under your domain.\n\n9. Deploy to AWS\n```\n./scripts/deploy\n```\nTest it \u003c/br\u003e\n`curl --request GET \"https://\u003cUNIQUE_ID\u003e.execute-api.\u003cAWS_REGION\u003e.amazonaws.com/dev/\"`\n\n10. Remove deployment from AWS\n```\n./scripts/remove\n```\n\n11. (Optional) Remove the domain from Route53 (it will not remove the certificate!)\n```\n./scripts/delete-domain\n```\n\n## Environments\nWhat | How (script) | Where (endpoint)\n--- | --- | --- \n**Local** | `./scripts/start` | `http://localhost:8000`\n**Remote**|`./scripts/deploy`|`https://***.execute-api.\u003cAWS_REGION\u003e.amazonaws.com/dev/`\n**Develop Domain**|`./scripts/create-domain`\u003c/br\u003e`./scripts/deploy`|`https://api-develop.your.domain`\n**Staging Domain**|`./scripts/create-domain staging`\u003c/br\u003e`./scripts/deploy staging`|`https://api-staging.your.domain`\n**Production Domain**|`./scripts/create-domain prod`\u003c/br\u003e`./scripts/deploy prod`|`https://api.your.domain`\n\n## Contributing\nWe welcome contributions to this project! If you have an idea for a new feature or improvement, please open an issue or pull request.\n\n## License\nThis project is licensed under the MIT License. See the LICENSE file for details.\n\n\n## Tips\n### Set python interpreter in VScode\n- Run `poetry run which python` and copy the python path\n- `command+shift+p` to open the VScode command shortcuts and enter `Python: Select Interpreter`\n- Select `+ Enter interpreter path...` and paste the python path\n- That's it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froy-pstr%2Ffastapi-serverless-aws-backend-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froy-pstr%2Ffastapi-serverless-aws-backend-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froy-pstr%2Ffastapi-serverless-aws-backend-service/lists"}