Answers: <p>Unless you are using the <a href="https://aws.amazon.com/api-gateway/" rel="noreferrer">AWS API Gateway</a>, you'll still need some way of "serving" your Flask API.  You will also need to provision an EC2 instance and run something to serve your API.  Instead of running a windows EC2 instance with IIS you can save about 50% operating cost and use Nginx on a linux EC2 instance.  Additionally, Nginx can be used as a <a href="https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/" rel="noreferrer">reverse proxy</a>, and supports <a href="https://docs.nginx.com/nginx/admin-guide/content-cache/content-caching/" rel="noreferrer">caching</a> which you may find beneficial.</p>
  
  <p>However, because you are using an Application Load Balancer and are looking into Gunicorn to serve the API you probably don't <em>need</em> Nginx, and it would just require more overhead for deployments if you are not going to setup any of the features in Nginx.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-09-20T14:38:23.870Z
Answers: Should have mentioned earlier, I will be using ECS + Fargate to run the container. The reverse proxy capability is already handled by ALB. Caching, however, might be a good point.
Answers: Domen P
Answers: CC BY-SA 4.0
Answers: 2019-09-20T13:18:03.547Z
Answers: 2019-09-20T13:18:03.547Z
Answers: Wesley Rolnick
Body: <p>I want to deploy a Flask API on AWS using Docker. A common way seems to be using a combination of Nginx + app server (e.g Gunicorn) + Flask app.</p>
  
  <p>The reason to use app server seems obvious to me. However, since I plan to use AWS ALB I'm not sure if there's a need for Nginx anymore? From my understanding Nginx is used for connection handling and serving static resources. In my case I don't need any of these: the connection is handled already by ALB (AFAIK) and I won't have to serve static resources.</p>
  
  <p>Are there any other advantages of using Nginx for a low latency API service?</p>
  
Tags: <amazon-web-services><python><nginx><amazon-ecs><flask>
Title: What's the benefit of using Nginx to serve a Flask API on AWS?
UserDisplayName: Domen P
ThreadText: # What's the benefit of using Nginx to serve a Flask API on AWS?
  
  (Asked by: username_0 on 2019-09-20)
  
  I want to deploy a Flask API on AWS using Docker. A common way seems to be using a combination of Nginx + app server (e.g Gunicorn) + Flask app.
  
  The reason to use app server seems obvious to me. However, since I plan to use AWS ALB I'm not sure if there's a need for Nginx anymore? From my understanding Nginx is used for connection handling and serving static resources. In my case I don't need any of these: the connection is handled already by ALB (AFAIK) and I won't have to serve static resources.
  
  Are there any other advantages of using Nginx for a low latency API service?
  
  **Tags:** amazon-web-services, python, nginx, amazon-ecs, flask
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-09-20. Score: 5
  
  Unless you are using the [AWS API Gateway](https://aws.amazon.com/api-gateway/), you'll still need some way of "serving" your Flask API. You will also need to provision an EC2 instance and run something to serve your API. Instead of running a windows EC2 instance with IIS you can save about 50% operating cost and use Nginx on a linux EC2 instance. Additionally, Nginx can be used as a [reverse proxy](https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/), and supports [caching](https://docs.nginx.com/nginx/admin-guide/content-cache/content-caching/) which you may find beneficial.
  
  However, because you are using an Application Load Balancer and are looking into Gunicorn to serve the API you probably don't *need* Nginx, and it would just require more overhead for deployments if you are not going to setup any of the features in Nginx.
  
  > **Comments:**
  > **username_0**: Should have mentioned earlier, I will be using ECS + Fargate to run the container. The reverse proxy capability is already handled by ALB. Caching, however, might be a good point.  
  
  ---
  
  