Search code examples
amazon-web-serviceswebserverserverlessinfrastructure

AWS simple serverless architecture recomendation


I'm learning about websites structures and I get confused by the number of concepts and designs that are.

This is what I want to do:

(Using AWS)

Image: AWS serverless simple structure

Route 53: DNS

CloudFront: CDN

website1.com/styles.css   ->  S3 /website1/styles.css
website1.com/robots.txt   ->  S3 /website1/robots.txt
website1.com/favicon.ico  ->  S3 /website1/favicon.ico

website1.com/             -> API Gateway
website1.com/api/*        -> API Gateway

S3: Where I save: syles.css, robots.txt, and favicon.ico

API Gateway: Request handler.

website1.com/       ->  Lambda (node.js)
website1.com/api/*  ->  Lambda (API)

Lambda (node.js): I want to have serverless Server Side Rendering React App with Node. This App calls to an API to get some data.

Lambda (API): the API

RDS: PostgreSQL

Question

1) Is my structure correct? Or there are any other website server designs that are better? (I want to conserve Server Side Rendering)

2) Can I add another website to this structure? Or I need to generate a new instance of each element of AWS?


Solution

  • You can use this setup but... I wouldn't recommend using API Gateway for server side rendered websites. Problem is that almost nobody these days is writing server side rendered websites without using established frameworks for their language of choice and there is really no good way how to use these frameworks, ex. ExpressJS in case of Node, with Lambda. In most cases, you would need to write your own code which equals to reinventing of a wheel, not to mention how error prone that is.

    Lambda functions should be small chunks of code, for maintainability and to reduce execution time of it which equals to cost reduction. Also note that there is a limit to lambda function size.

    Common setup is to use SPAs hosted on S3 and API gateway with Lambda for backend logic. If you need to use server side rendering then it might be better to use some other service which allows you to write your backend application in an "old" fashioned way (EC2, Beanstalk, ECS, EKS...), using mentioned frameworks.

    And yes, you can include as many websites as you wish in this setup. You can either do the routing based on URL directly on API gateway, having separate resources for different websites or you can do the routing on CloudFront, having one API Gateway per website.