I want to setup a flask instance on aws and all of the advice is to make it on a container but the containers cost more for performance over linux so I’m unsure of which to choose (is linux really that much harder)
I am running Flask applications in Production with ECS with Fargate, it works really well. You could start with something like 2VCPU, 4GB Ram spec, and then fine tune it or scale it after you run a load test
Going for an EC2 instance is really waste of resources in my opinion
I think you’re asking containers vs. “bare metal” EC2 as both containers and EC2 will be running Linux on your case.
While “bare metal” VMs can allow you to better maximise performance of the available resources, in practice it’s much harder without the knowledge and time to achieve it. You will need to consider the trade offs of vertically scaling vs horizontally scaling before anything else. Automatic horizontal scaling of EC2 (ASG) will be required and tuned to ensure you’re spinning up instances quickly enough to handle load. Building the AMIs, instance configuration and boot scripts are very time consuming.
Flask + uwsgi in a container running on ECS Fargate, on the other hand, will be much easier for you to build, test locally, deploy to AWS, then scale quickly with load. The whole infrastructure, build and deployment process can be written into a single CDK or Terraform script so you can push changes in less than 5 minutes.
You should also consider Lambda especially as there’s some great shims for Flask which accelerates Lambda development. Check out: http://serverless.com//blog/flask-serverless-api-in-aws-lambda-the-easy-way and https://www.cloudtechsimplified.com/run-python-flask-in-aws-lambda/.
Of course, with Lambda you can scale to thousands of requests per second with minimal delay and without the cost and fine tuning required for EC2 or ECS.
Much of the discussion will devolve down to time or money.
Deploying via containers to Fargate will be much easier and simpler but will cost more (because Bezos didn’t become a billionaire by giving shit away).
If you deploy to a linux EC2 instance, you’ll spend less money running it but much more time configuring everything to run and then maintaining it.
Maintaining the EC2 instance will involve tasks like:
* deleting log files before they fill up disk
* applying security updates to the OS so you don’t get pwned by some asshole on the internet
* upgrading Flask and other Python libraries because of security updates or functionality fixes
* deploying new code and configs
There are plenty of tools and scripts you can use to automate a lot of these tasks, but do you know which tools to use and how to use them now? If not, you’ll need to spend time figuring out which tools to use and then apply them to your build and deploy process,
just choose ec2 or lightsail
the install for a prod flask server isn’t that hard
update apt. install nginx and pip. install gunicorn and flask. setup nginx.conf as a reverse proxy. create systemd service file for gunicorn
plenty of scripts for ubuntu or amazon linux to find online