I have created a flask application that uses a sqlite database in local system. It works fine.
I wanted to deploy this application on AWS on Elastic Beanstalk service. The application is deployed successfully using GitHub actions and Elastic Beanstalk. However, when I try to access the database, it shows Internal Server Error.
I know that to locally create the database, we need to run the following 3 commands -
flask db init
flask db migrate -m "Message"
flask db upgrade
But where should I mention and run these commands in Elastic BeanStalk? Should I mention them in the main.yml file?
Related
Context
I have a backend and API written in Python and Flask-SQLAlchemy. I use Flask-SQLAlchemy to define tables for a MySQL database, and my API routes access these tables. Previously, all my development has been on my local machine and my Flask-SQLAlchemy communicated with a local SQLite database. I currently have a Docker container with a MySQL image which contains an empty MySQL database.
What I Am Trying To Accomplish
I would like to host this API online, as well as host the Docker container (which contains a MySQL database) online. The Flask-SQLAlchemy API should communicate with the hosted MySQL database.
Options I've Considered
To my understanding, there are several options to host my API and MySQL database online.
For my API, I can either host my API onto AWS Elastic Beanstalk, or onto Docker then onto EC2.
For my MySQL database, I would like to host it onto Docker then onto EC2.
The following is how I assume I can approach this:
Problem
Should I host my Flask-SQLAlchemy API on Elastic Beanstalk, or on Docker then onto EC2? My main goal is to have my hosted API talk to a MySQL database hosted on Docker.
I would like to deploy a Web Flask Application to AWS Elastic Beanstalk. I found a Docker Image with Flask + Nginx + WSGI that start these three services when I up a container service.
I have two questions:
Is it a good practice to start more than one service in the same container? In this case: Flask + Nginx + WSGI (development/production)
I read that AWS Elastic Beanstalk already has Nginx configured by default (besides load balancing, auto-scaling, etc).
Is it ok to start a Container with only Flask application? If so, where does the WSGI configuration go?
I read this article:
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-flask.html
And seeing this:
WARNING: Do not use the development server in a production environment. Use a production WSGI server instead.
I understood that the development environment was deployed in production. Which seems wrong.
I want to deploy my django with MySQL db for production on aws ec2. Files and db are present on the server.
follow the official docs http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html, start directly at "Configure Your Django Application for Elastic Beanstalk", since you have already developed your app
Currently I have setup my yii2 website on AWS Elastic beanstalk. I followed following steps :
Created Elastic Beanstalk app and environment : Platform PHP 7.0, RDS database
Created SSH connection from EC2 instance of elastic beanstalk using putty with .pem file
In Apache folder I have cloned my yii2 git repo using (sudo git clone repo_url) command
Installed composer using this link https://gist.github.com/asugai/6694502
Run command : (sudo composer install) in my repo folder
Edited common/config/main-local.php and made db connection
And run migration using (sudo php yii migrate)
Setup a domain for this elastic beanstalk app
Now I don't know how should I proceed further and I am facing following problems :
Elastic Balance loader is creating new instance and terminating current one when it fails or health goes in severe.
Due this, my all data in that instance is lost. To make it work I am doing all steps again and again manually.
How can I make my domain https (SSL certified)
How can make easy process to pull new changes from git
I already have a working site in nodeJS. which is using elastic beanstalk, elastic balance loader, RDS(postgres), S3 bucket, cloudfront for Route 53, SSL certificate (https), code pipeline, code commit. And AWSCLI at local to deploy nodeJS app.
my question is about I want to use same flow for yii2 advance app.
Can anyone please help me here?
Thanks in advance :)
AWS Elastic Beanstalk is easy to use for deploying rails app on Amazon EC2. By set RAILS_SKIP_MIGRATIONS as true, eb won't run the migrations itself so I can manage migrations myself.
However,SSH to the EC2 instance that created by Beanstalk, I can't find the deployed rails app in the home directory.Then I don't know where to manually rake the migrations.
I wonder why the rails app can't be found on the EC2 instance since the instance is the web server to host the app. Is it hidden somewhere? And how should I manually rake the migrations?
Thanks
Try take a look at /var/app/current.
I think you can't find rake, because elastic beanstalk run ruby environment in virtual environment - rvm. Try to find in the directory /opt environment variables which set up ruby environment for current terminal. I'm not sure for ruby, but for python you should do: source /opt/python/current/env.