Serving dynamic webpages using aws?

Viewed 862

I'm new to AWS in general, and would like to learn how to deploy a dynamic website with AWS. I'm coming from a self-hosted perspective (digitalocean + flask app), so I'm confused on what exactly the process would be for AWS.

With self-hosting solution, the process is something like:

  • User makes a request to my server (nginx)
  • nginx then directs the request to my flask app
  • flask app handles the specific route (ie, GET /users)
  • flask does db operations, then builds an html page using jinja2 with the results from the db operation
  • returns html to user and user's browser renders the page.

With AWS, I understand the following:

  • User makes a request to Amazon's API Gateway (ie, GET /users)
  • API Gateway can call a AWS Lambda function
  • AWS Lambda function does db functions or whatever, returns some data
  • API Gateway returns the result as JSON (assuming I set the content-type to JSON)

The confusing part is how do I generate the webpage for the user, not just return the JSON data? I see two options:

1) Somehow get AWS Lambda to use Jinja2 module, and use it to build the HTML pages after querying the db for data. API Gateway will just return the finished HTML text. Downside is this will no longer be a pure api, and so I lose flexibility.

2) Deploy Flask app onto Amazon Beanstalk. Flask handles application code, like session handling, routes, HTML template generation, and makes calls to Amazon's API Gateway to get any necessary data for the page.

I think (2) is the 'correct' way to do things; I get the benefit of scaling the flask app with Beanstalk, and I get the flexibility of calling an API with the API Gateway.


Am I missing anything? Did I misunderstand something in (2) for serving webpages? Is there another way to host a dynamic website without using a web framework like Flask through AWS, that I don't know about?

2 Answers
Related