How to host an API (written in Flask-SQLAlchemy) to communicate with a Docker-ized MySQL container? - amazon-web-services

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.

Related

How to add a SQLite database in AWS?

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?

Containerised Web Application which connects to Relational DB

Can anyone point me in the direction of some demo code/app that I can use for a demo.
The app should have the ability to connect to a relational database and ideally be able to demonstrate the persistence of having the DB.
I.e. You can save values into the DB from the web app
I'm planning to deploy this onto AWS ECS for testing, alongside RDS.
Thanks in advance
Here is an AWS tutorial that shows how to write a Java Spring Boot Web app that is deployed to Elastic Beanstalk ( Elastic Beanstalk is an AWS service that leverages Amazon EC2 and S3 and deploys, manages and scales your web applications for you. It uses managed containers that support Node. js, Java, Ruby, Docker and more) and uses RDS to store and update data.
Creating the Amazon Relational Database Service item tracker
So most of what you are looking for is there - including how to setup the RDS instance and interact with it from a web app deployed to the cloud. If you follow this step by step (there is a lot of Java code) -- you will get this Sample Web App running on the cloud and it will teach you how to interact with RDS from a web app.
Also - this covers invoking additional services such as Simple Email Service from the web app.

Django with MySQL deploy on aws ec2

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

Database connections with RDS not working after deploying

I have developed a Dynamic web App, which leverages Amazon RDS. Servlet talks with RDS fetches data and presents it using JSP. The process is working fine. Next, I uploaded the war file of project on AWS Elastic beanstalk. But Database connections are not working.
Could you please guide me here? Why my connection variables are not working after deploying?
I made few changes to the early deployment and now App takes forever to load.

Database URL of a postgresql database residing in an Azure VM

I have an Azure VM that runs Ubuntu and has a Django app of mine along with its postgresql database installed on it.
Moreover, I also have an Azure Web App that was created with Django, which I then connected to github, and pulled the source code for the same app I have on the aforementioned Azure VM.
I now want the settings.py in this Django Azure Web App to point to the database residing in the Azure VM.
Normally, the way to do this is to list the database url in the app's settings.py. My question is: what would be the database url for my postgresql database installed in the Azure VM, if one was to try and access it from an Azure Web App (i.e. external to the Azure VM)? Would it be: postgres://AzureVM'sFQDN:5432/nameofdatabase?
Provided you have opened port 5432 on the VM, that would be the right string to connect to your database from anywhere. Have you tried to connect your development machine to this database?
If you have created your set-up with the new resource manager deployment model of azure, you should also be able to create both the web-app and the database VM within the same virtual network. This way, you can provide access to the database only for the Web App, and not for the entire internet.