Skip to content

A Web API built with Flask, Gunicorn and NGINX and hosted on AWS

Notifications You must be signed in to change notification settings

mw866/images_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Images API on AWS

Chris Wang (mw866)

Description: An API based on Flask, Gunicorn and NGINX

Usage: http:///api/num_colors?src=

Example: http:///api/num_colors?src=https://www.wikipedia.org/portal/wikipedia.org/assets/img/[email protected]

Remember to build the runtime cache: $siege -t1m --concurrent=20 -b -i --file=./output/chris/siege_urls.txt

Logs files:

  • NGINX: tail -f /var/log/nginx/error.log

  • Gunicorn: tail -f /var/log/gunicorn/error.log

Architecture

  • DNS: AWS Route 53

  • Reverse Proxy & Load Balancer (t2.micro x1): NGINX

  • Web Server (t2.micro x3): Gunicorn

  • Web Framework: Flask

Requirements

References

Flask with Gunicorn

*Gunicorn accept Nginx forwarding: http://docs.gunicorn.org/en/stable/deploy.html

NGINX

Vagrant

AWS EC2

AWS Route 53

Requests

### ImageMagick and PIL

* ImageMagick with Python Example: https://github.com/jinpark/imageresizer

* ImageMagick Wand API Documentations: http://docs.wand-py.org/en/0.2.4/index.html

* PIL: http://effbot.org/zone/pil-index.htm

Troubleshooting

Nginx

Gunicorn

  • ImportError: No module named wsgi: Run within /vagrant/

  • Does not receive from NGINX: --bind 0.0.0.0:8000

Vagrant/Linux

  • Network testing: Vagrant by default creates multiple interfaces, hence use ping -I <specific hostonly/private interface> to avoid confusion.

  • Network interface config: /etc/network/interfaces

  • .1 address cannot be used because of conflicts with host machine's vboxnet1 interface

AWS

Performances

Siege command used by Load Test script

$siege -t1m --concurrent=3 -b -i --file=./output/chris/siege_urls.txt --log=./output/chris/siege.log --user-agent=Magic Browser

Parameters can be tuned

Gunicorn: --worker 3 Python Requests: requests.get(timeout = 0.01)

Releases

No releases published

Packages

No packages published