I have a fairly simple FastAPI project I am working on. It works just fine locally when I run it. However, when I attempt to deploy this project to AWS Elastic Beanstalk, the environment fails to run and I get 502 Bad Gateway responses when I attempt to open the webpage.
from fastapi import FastAPI, Request, File, UploadFile
from fastapi.staticfiles import StaticFiles
from starlette.responses import FileResponse
from models import *
app = FastAPI()
app.mount("/static", StaticFiles(directory="static", html=True), name="static")
@app.get("/")
async def root():
return FileResponse('static/index.html')
@app.post("/files")
async def create_file(file: bytes = File()):
employeeCsv(file)
return {"file_size": len(file)}
Again, this runs just fine locally. When I deploy this project I get "Environment update completed successfully" but again, I have a 502 bad gateway response when accessing the webpage.
Here is, what I think, are the relevant logs.
Traceback (most recent call last):
File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
worker.init_process()
File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/uvicorn/workers.py", line 66, in init_process
super(UvicornWorker, self).init_process()
File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app
mod = importlib.import_module(module)
File "/usr/lib64/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/var/app/current/main.py", line 30, in <module>
async def create_file(file: bytes = File()):
TypeError: File() missing 1 required positional argument: 'default'
I have been completely unsuccessfuly so far in figuring out why it is missing an argument there. All I am trying to do is upload a csv file via a button in my html and then work with it. If anyone can share insight or point me towards a solution I would be very thankful