From 45654a8785edff29c3a33b4845152d36660f97c4 Mon Sep 17 00:00:00 2001 From: eduard0803 Date: Wed, 17 Apr 2024 17:47:25 -0300 Subject: [PATCH] adding tutorial to deploy fastapi-server in aws-EC2 --- EC2/Makefile | 5 +++++ EC2/README.md | 1 + EC2/fastapi_nginx | 8 ++++++++ EC2/requirements.txt | 2 ++ EC2/server.py | 27 +++++++++++++++++++++++++++ 5 files changed, 43 insertions(+) create mode 100644 EC2/Makefile create mode 100644 EC2/README.md create mode 100644 EC2/fastapi_nginx create mode 100644 EC2/requirements.txt create mode 100644 EC2/server.py diff --git a/EC2/Makefile b/EC2/Makefile new file mode 100644 index 0000000..d1651a8 --- /dev/null +++ b/EC2/Makefile @@ -0,0 +1,5 @@ +host := $(value HOST) +key := $(value KEY) + +ssh: + ssh -i "${key}" ${host} diff --git a/EC2/README.md b/EC2/README.md new file mode 100644 index 0000000..6f13717 --- /dev/null +++ b/EC2/README.md @@ -0,0 +1 @@ +### Tutorial to deploy fastapi server in aws-ec2 diff --git a/EC2/fastapi_nginx b/EC2/fastapi_nginx new file mode 100644 index 0000000..77dfb4a --- /dev/null +++ b/EC2/fastapi_nginx @@ -0,0 +1,8 @@ +server { + listen 80; + server_name 52.42.65.162; + location / { + proxy_pass http://0.0.0.0:8000; + } +} + diff --git a/EC2/requirements.txt b/EC2/requirements.txt new file mode 100644 index 0000000..d40ad3d --- /dev/null +++ b/EC2/requirements.txt @@ -0,0 +1,2 @@ +fastapi==0.99.1 +uvicorn==0.22.0 \ No newline at end of file diff --git a/EC2/server.py b/EC2/server.py new file mode 100644 index 0000000..ab12044 --- /dev/null +++ b/EC2/server.py @@ -0,0 +1,27 @@ +from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware + +app = FastAPI() + +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"] +) + + +@app.get("/") +def root(): + return {"message": "Hello World"} + + +if __name__ == "__main__": + import uvicorn + uvicorn.run( + app="server:app", + host="0.0.0.0", + port=8000, + reload=True, + )