How to Deploy a Flask Application on AWS Elastic Beanstalk? - amazon-web-services

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.

Related

Elastic Beanstalk enviroment with OpenLiteSpeed

I wanted to ask you if it is possible to create an OLS web server app using AWS Elastic Beanstalk. I'm planning on launching a WordPress site with it.
I have just created one but it creates it with NGINX and gives me the option to change it to Apache.
Do you know if it is even possible?

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?

how to deploy MEAN stack app on AWS elastic beanstalk?

I'm trying to deploy my mean stack app on AWS using elastic beanstalk but there doesn't seem to be a tutorial good enough that can help me through it.
I would also like to know if I should really deploy it on elastic beanstalk or Lightsail?
Can you share any articles, videos or anything good enough to help me. It will be helpful to a lot of people.
Angular Version : 7
Node Version: 10.14.1
elastic beanstalk will be the option for production while you can use light sail for testing dev enviroment
now if we talk about the deploying Mean stack app
Open Elastic Bean stalk console and you will get option to choose Webserver
Choose web server with apache, tomcat, nginx, configure it as per your requirement
at last you will get option for upload your application
Upload your app using zip file (if dist folder is output then direct deploy dist in elastic beanstalk)

Deploy flask-socketio on beanstalk

I can't quite get Flask-SocketIO working with my instance on AWS Elastic Beanstalk (ELB), with the requirement of running Flask-SocketIO with socketio.run(application), ELB appears to make the calls to the global application object itself.
The ELB documentation states Using application.py as the filename and providing a callable application object (the Flask object, in this case) allows Elastic Beanstalk to easily find your application's code.
My ELB instance logs show the error RuntimeError: You need to use the eventlet server. See the Deployment section of the documentation for more information.
Is there any way to approach this problem assuming that AWS calls application.run()?
Thanks in advance
Flask-SocketIO has very specific requirements on the load balancer and the web server. I think you can configure the ELB load balancer with sticky sessions and that would make it work, but the part that I think does not work is using the eventlet or gevent web servers, since AWS invokes the callable in its own way. What you need is a way to use socketio.run() or an equivalent procedure that starts the eventlet/gevent web server.
There has been some changes to AWS beanstalk lately. Per default it uses gunicorn and nginx.
I got the setup working using a single instance setup without loadbalancers. The loadbalancer config in beanstalk allows stickiness configuration but my applications design would work only on a single instance anyway, so I didn't care.
To create a single instance beanstalk environment:
eb create --single my_env
Then, configure the way gunicorn is started: Create a file Procfile (see aws docs)
For eventlet use this:
web: gunicorn --worker-class eventlet -w 1 application:application
And place this into requirements.txt:
gunicorn==20.1.0
eventlet==0.30.2
The particular versions are needed to prevent the cannot import name 'ALREADY_HANDLED' error, see here.
See flask-socketio doc for other deployment options besides gunicorn/eventlet.

Recommendation: Deploy Docker application to AWS

I got a local Docker stack running Node.js, MongoDB and Nginx.
It runs perfectly using docker-compose up --build.
Now it's time to deploy my application to a production environment.
I have considered EC2 Container Service and EC2, but can you recommend an easier approach? The learning curve is steep!
For MongoDB -
Use AWS quick start MongoDB
http://docs.aws.amazon.com/quickstart/latest/mongodb/overview.html
http://docs.aws.amazon.com/quickstart/latest/mongodb/architecture.html
For rest of the docker stack i.e NodeJS & Nginx -
Use the AWS ElasticBeanstalk Multi Container Deployment
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_ecs.html
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_v2config.html
Elastic Beanstalk supports Docker, as documented here. Elastic Beanstalk would manage the EC2 resources for you so that you, which should make things a bit easier on you.
You can install Kontena to AWS and use that to deploy your application to production environment (of course other cloud providers are also supported). Transition from Docker Compose is very smooth since kontena.yml uses similar syntax and keys as docker-compose.yml.
With Kontena you will have private image registry, load balancer and secret management built-in that are very useful when running containers in production.