简体   繁体   中英

Deploying Python on AWS Elastic Beanstalk

I'm coming from a php background and now I'd like to host a Python web application on AWS but have a few questions about it.

  1. Do I need to use a framework like Django/Flask? Is there anyway I can use core Python to do the same? Back in php, although I tried learning Laravel in the middle, I was able to just use core php with apache and host up my website.
  2. Tried deploying my Python code on my AWS but got an error that application.py was missing. I'd like to know, what exactly is application.py and what is it supposed to contain? Similarly, what's wsgi.py I see here and there. Are these actual files I need to create for the web app to be hosted? Is there some specific code that has to go into them or are the pre-created files by frameworks like Django, etc? Because I could hardly find too much information on them online.

I had recently tried following this tutorial from the AWS official site but to no luck.

The reason for being reluctant to use Django is the shortage of time to learn it. But if it were to make the task of hosting a Python web app easier, I would definitely look at it. And how is the version of Python set? Because the Python codes I've written use the python3 libraries for BeautifulSoup and urllib.

I have read a lot of articles on the web but the first thing I get on searching for Python on the web or with AWS, is Django or Flask or something. How exactly does it work? When it came to php, it was simple copying the files into the /www/ folder of the server machine and I could access the website via it's url. Maybe I've read too many posts to put them all together so could someone please set it straight for me? It would be greatly appreciated!

Thanks a lot!

You will waste a lot more time trying to write a WSGI application yourself from scratch. Use a framework, it will save you a lot of time.

PHP is very different to WSGI and WSGI sits well below the level of functionality that PHP provides out of the box. PHP is more like what frameworks in Python provide. So go learn a framework. If Django seems too complicated, try Flask first.

Also don't try and do it on AWS from the outset, learn the frameworks by using the development servers they provide on your own box. Just work through their respective tutorials.

  1. Actually AWS Elastic Beanstalk give you pure Python (2.6/2.7/3.4) with Apache + mod_wsgi as web proxy. You can look all supported Python environment in here . So, you can use any Python web framework (such as Django, Flask, etc.) in your web app. If you can, choose common and supported framework by AWS (Django/Flask).

    You can think: Python + Apache + mod_wsgi is equivalent to PHP + Apache + mod_php .

  2. Please take a look into AWS Elastic Beanstalk documentation for how to working with Python here . Read the Deploying a Django Application or Deploying a Flask Application if you choose one of them. You need to provide what Elastic Beanstalk environment (mod_wsgi) needs.

Same as PHP, Python actually only copy and paste the files. If you want to make Python web app without framework, you need to follow the WSGI standard. You can take look into this question . In my opinion, better if you use a framework, because it handles the WSGI part for you.

First of all this is a good blog post to start from if you are using Django

  1. I don't know much about Flask, with Django once you understand the core concepts it's not hard at all.

  2. application.py is the file that aws looks for as stated in the blog post I pointed to: By default eb assumes our wsgi file is called application.py this can be changed to your local wcgi.py file that Django makes when you start your project with django.

  3. Beware that you want to use your static url correctly so aws will read them from the right folder. I personally disagree about the way the static files configuration in the post. It's better to stay with the aws default which is "static" and just set static url in django settings to "/static/"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM