I am trying to deploy my Flask-SQLAlchemy backend and React frontend using Elastic Beanstalk. I already created a working S3 Bucket with CloudFront for the React frontend. I have been (unsuccessfully) trying to create the backend on Elastic Beanstalk (also open to other services in AWS if you think better), but keep having a Degraded health. I think the issue has something to do with the way my file is structured. This is the general structure:
~/server/
|-- app.py
|-- requirements.txt
|-- app_setup.py
|-- models
|-- routes
|-- schemas
|-- seed.py
|-- .ebextensions
|--python.config
|-- Pipfile
|-- Pipfile.lock
This is what my python.config file looks like: option_settings: "aws:elasticbeanstalk:container:python": WSGIPath: app_setup:application I pointed it to app_setup, since this is where I defined my Flask application, like so:
application = Flask(
__name__,
static_url_path="",
static_folder="../client/build",
template_folder="../client/build",
)
As a note, I am using RESTful routes and have tried to abstract all the code into different folders. So my actual Application.py (named this way cause I watched Youtube video that said AWS picks up on it better if you call it Application instead of App???) looks like this:
#!/usr/bin/env python3
# Standard library imports
# Local imports
from app_setup import application, db, ma, api, jwt, s3
from models.user import User
from flask import render_template
# Route Imports
# from routes.donation_by_id import DonationById
from routes.one_time_donations import OneTimeDonations
from routes.event_attendee_by_id import EventAttendeeById
from routes.event_attendees import EventAttendees
from routes.event_by_id import EventById
from routes.events import Events
from routes.joined_project_by_id import JoinedProjectById
from routes.joined_projects import JoinedProjects
from routes.project_by_id import ProjectById
from routes.projects import Projects
from routes.user_by_id import UserById
from routes.users import Users
from routes.s3_upload import S3Upload
from routes.first_login import FirstLogin
# auth routes
from routes.auth.register import Register
from routes.auth.login import Login
from routes.auth.google_auth import GAuth
from routes.auth.logout import Logout
from routes.auth.current_user import CurrentUser
from routes.auth.refresh import Refresh
# stripe routes
from routes.stripe.create_checkout_session import CreateStripePay
from routes.stripe.webhook import StripeWebHook
from routes.stripe.get_checkout_session import GetCheckoutSession
from routes.subscription_donations import SubscriptionDonations
# Add Resources
# api.add_resource(DonationById, "/donations/<int:id>")
# api.add_resource(Donations, "/donations")
api.add_resource(EventAttendeeById, "/eventattendees/<int:user_id>/<int:event_id>")
api.add_resource(EventAttendees, "/eventattendees")
api.add_resource(EventById, "/events/<int:id>")
api.add_resource(Events, "/events")
api.add_resource(JoinedProjectById, "/joinedprojects/<int:user_id>/<int:project_id>")
api.add_resource(JoinedProjects, "/joinedprojects")
api.add_resource(ProjectById, "/projects/<int:id>")
api.add_resource(Projects, "/projects")
api.add_resource(UserById, "/users/<int:id>")
api.add_resource(Users, "/users")
api.add_resource(S3Upload, "/api/s3-upload")
# Auth Resources
api.add_resource(Register, "/register")
api.add_resource(Login, "/login")
api.add_resource(GAuth, "/googleauth")
api.add_resource(Logout, "/logout")
api.add_resource(CurrentUser, "/current-user")
api.add_resource(Refresh, "/refresh")
# Stripe Resources
api.add_resource(CreateStripePay, "/create-checkout-session")
api.add_resource(StripeWebHook, "/webhook")
api.add_resource(GetCheckoutSession, "/get-checkout-session/<string:session_id>")
api.add_resource(SubscriptionDonations, "/subscription-donations")
api.add_resource(OneTimeDonations, "/one-time-donations")
# Email Resources
api.add_resource(FirstLogin, "/first-login/<string:email>")
# Views go here!
u/jwt.user_lookup_loader
def user_lookup_callback(_jwt_header, jwt_data):
identity = jwt_data["sub"]
return db.session.get(User, identity)
u/application.route("/health-check")
def health_check():
return 'OK'
u/application.route("/")
u/application.route("/about")
u/application.route("/projects")
u/application.route("/projects/:slug")
u/application.route("/dashboard")
u/application.route("/resources")
u/application.route("/profile")
u/application.route("/leaderboard")
u/application.route("/success")
u/application.route("/cancel")
u/application.route("/signup")
u/application.route("/login")
u/application.route("/admin")
u/application.route("/feedback-form")
u/application.route("/forgot-password")
def index(id=0):
return render_template("index.html")
if __name__ == "__main__":
application.run(port=5555, debug=True)
Thank you so so so much! Any help is appreciated. I have been stuck on this issue for forever and don't really know what to do anymore. This is the error I am getting:
- Process default has been unhealthy for 7 minutes (Target.FailedHealthChecks).
- Following services are not running: web. Please let me know if I can provide any other info to help solve this problem. Thank you :')
I have tried to rearrange my file structure a few times now. I suspect something is wrong with how AWS is understanding my files. When I run my files locally, it has no issues with accessing the backend. Also, as a note, I already connected the backend to RDS as well. So really just trying to figure out this last part.