- Notifications
You must be signed in to change notification settings - Fork0
A Sample FastAPI + GraphQL + AWS CDK Project
License
CloudBytesCollection/sample-fastapi-graphql-book-api
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A sample python book-api project using FastAPI and GraphQL. This project leverages docker for containerization and provides the full setup to deploy to AWS Fargate using AWS CDK. The starter is created for and used in theBuilding Serverless Python Apps Using FastAPI and AWS book byEidan J. Rosado.
To avoid setting up MongoDB and other such services locally, the team uses Docker. You'll need to install Docker to proceed pulling the image from the team's hub. Contact one of the team admins for access to the hub. To start peripheral services simply execute the following:
docker-compose up
To refresh the image on your local (for server devs), run the following:
docker build -t bookapi -f Dockerfile.You can run the one off image and container with the following:
docker run -d --name bookapi -p 8000:8000 bookapi
You'll need the following environment variables configured or in a .env file to run the server successfully:
# FastAPI Setupexport HOST="127.0.0.1"export PORT=8000# BookAPI DB Setupexport DB_URL='mongodb://localhost:27017'export DB_NAME='bookapi'# AWS and Infra SetupAWS_ACCOUNT='YOUR_ACCOUNT'AWS_REGION='AWS REGION (e.g. us-east-1)'DOMAIN_NAME='example.com'# Infra SetupLOCAL_NETWORK_CIDR='YOUR_NETWORK_CIDR'
The main entry point is main.py, so you can start that file from command line or use whatever execution method is available from your IDE. To install the IDE to interact with GraphQL, look in the SETUP.md for GraphQL Playground installation instructions then simply open the GraphQL Playground to interact with the local server and insert the base urlhttp://127.0.0.1:8000/graph.
Changes under /app may be picked up by the auto-refresh (no need to restart server). To understand how to use the playground to run queries, please reference the following:GraphQL Queries Reference
All tests are located under thetests folder. To run them from terminal, execute the following:
pytest tests
To run with coverage, run the following:
coverage run -m pytest -v tests&& coverage report -mThe docs are autogenerated and are available after starting the server. Docs are available at{BASE_URL}/graphql/docs.
To update the doc url, update theget_graphql_docs() function inmain.py.
Note that the Makefile included in this repo uses several environment variables. Be sure to have your .env setup to fully leverage all the shortcuts made available.
About
A Sample FastAPI + GraphQL + AWS CDK Project
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.