{"id":25833866,"url":"https://github.com/llanlan1/fastapicrud","last_synced_at":"2026-05-07T13:11:38.259Z","repository":{"id":278232822,"uuid":"934928412","full_name":"llanlan1/fastapiCrud","owner":"llanlan1","description":"FastAPI CRUD API with Docker, deployed on AWS EC2. Includes setup, deployment guide, and troubleshooting steps","archived":false,"fork":false,"pushed_at":"2025-02-18T18:55:08.000Z","size":16485,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-01T00:37:09.590Z","etag":null,"topics":["docker","docker-container","ec2","ec2-instance","fastapi","python-script"],"latest_commit_sha":null,"homepage":"","language":"Python","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/llanlan1.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":"2025-02-18T16:20:49.000Z","updated_at":"2025-02-18T18:55:11.000Z","dependencies_parsed_at":"2025-02-18T18:34:33.271Z","dependency_job_id":null,"html_url":"https://github.com/llanlan1/fastapiCrud","commit_stats":null,"previous_names":["llanlan1/fastapicrud"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/llanlan1/fastapiCrud","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llanlan1%2FfastapiCrud","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llanlan1%2FfastapiCrud/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llanlan1%2FfastapiCrud/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llanlan1%2FfastapiCrud/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/llanlan1","download_url":"https://codeload.github.com/llanlan1/fastapiCrud/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llanlan1%2FfastapiCrud/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271755437,"owners_count":24815407,"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","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["docker","docker-container","ec2","ec2-instance","fastapi","python-script"],"created_at":"2025-02-28T23:32:53.348Z","updated_at":"2026-05-07T13:11:33.226Z","avatar_url":"https://github.com/llanlan1.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FastAPI CRUD API Deployment on EC2 with Docker\n\nThis guide documents the steps to deploy a FastAPI CRUD API on an EC2 instance using Docker, including troubleshooting issues encountered along the way.\n\n## Prerequisites\n- AWS account with access to EC2\n- Docker installed on your local machine\n- Basic understanding of FastAPI\n- SSH access to your EC2 instance\n- Python installed locally for development\n\n## Step 1: Set Up Project Structure\nCreate a new directory for your FastAPI project:\n```sh\nmkdir fastapi-crud\ncd fastapi-crud\n```\nInside this directory, create the following structure:\n```\nfastapi-crud/\n│-- app/\n│   │-- main.py  # Entry point of the FastAPI app\n│   │-- models.py  # Database models\n│   │-- database.py  # Database connection\n│   │-- schemas.py  # Pydantic models for request validation\n│   │-- crud.py  # CRUD functions\n│   │-- routers/\n│   │   │-- items.py  # API routes for handling CRUD\n│-- requirements.txt  # Dependencies\n│-- Dockerfile  # Docker configuration\n│-- .env  # Environment variables\n│-- README.md  # Documentation\n```\nThe file contents can be copied from this repo.\n\n## Step 2: Set Up an EC2 Instance\n1. Log in to your AWS console and navigate to EC2.\n2. Launch a new instance using an Amazon Linux 2 or Ubuntu AMI.\n3. Select an instance type (e.g., `t2.micro` for free tier users).\n4. Configure security group:\n   - Allow SSH (port 22) from your IP.\n   - Allow HTTP (port 80) and/or HTTPS (port 443).\n   - Allow your FastAPI app port (e.g., 8000).\n5. Create or use an existing key pair for SSH access.\n6. Launch the instance and note its public IP address.\n\n## Step 3: Connect to Your EC2 Instance\n```sh\nssh -i your-key.pem ec2-user@your-ec2-ip\n```\nFor Ubuntu:\n```sh\nssh -i your-key.pem ubuntu@your-ec2-ip\n```\n\n## Step 4: Install Docker on EC2\n```sh\nsudo yum update -y  # For Amazon Linux\nsudo apt update -y  # For Ubuntu\nsudo yum install -y docker  # Amazon Linux\nsudo apt install -y docker.io  # Ubuntu\nsudo systemctl start docker\nsudo systemctl enable docker\nsudo usermod -aG docker ec2-user  # Add user to Docker group\n```\nLogout and log back in to apply group changes.\n\n## Step 5: Copy Your FastAPI Project to EC2\nUse SCP (or Git if you have a repo):\n```sh\nscp -i your-key.pem -r fastapi-crud ec2-user@your-ec2-ip:~\n```\n\n## Step 6: Build \u0026 Run the Docker Container on EC2\n```sh\ncd fastapi-crud\ndocker build -t fastapi-app .\ndocker run -d -p 8000:8000 --restart always fastapi-app\n```\n\n## Step 7: Allow Inbound Traffic on EC2 (Security Group Settings)\n1. Go to AWS EC2 Dashboard → Security Groups.\n2. Add an **Inbound Rule** for **port 8000** with **Source: 0.0.0.0/0** (or your IP for security).\n\n## Step 8: Access Your FastAPI App\nVisit in your browser:\n```sh\nhttp://your-ec2-public-ip:8000\n```\nVisit FastAPI Swagger UI:\n```sh\nhttp://your-ec2-public-ip:8000/docs\n```\n\n## Troubleshooting Steps\n- **Cannot access FastAPI from browser:**\n  - Check if the security group allows traffic on port 8000.\n  - Run `docker ps` to ensure the container is running.\n  - Inspect logs with `docker logs \u003ccontainer_id\u003e`.\n- **Docker command not found:**\n  - Ensure Docker is installed and running (`sudo systemctl start docker`).\n- **Permissions issue with Docker:**\n  - Run `sudo usermod -aG docker $USER` and restart your session.\n\n## Conclusion\nYour FastAPI CRUD API is now running on an EC2 instance using Docker! 🎉\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fllanlan1%2Ffastapicrud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fllanlan1%2Ffastapicrud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fllanlan1%2Ffastapicrud/lists"}