How to convert an existing AWS EC2 server to Serverless

    • stunntech blog author image
    • Sasank Thaliyil

  • |
  • April 3, 2019

The era of traditional servers is gone. I mean, who wants to manage a server and scale it based on the usage? That’s why companies like Amazon, Microsoft and Google brings Serverless computing to reduce the infrastructure cost, and make autoscaling servers really work which helps developers focus on the business logic and not on the server maintenance. 

 

 

Why would you switch to Serverless architecture? 

 

- Don't pay for what you don't use.

- Less admin work on the server.  

- Focus on the business logic instead of the infrastructure.

- Deliver faster.

- Auto-scaling. 

- High availability.

 

How to switch a traditional EC2 server to Serverless architecture? 

 

  1. Take all the static content in the application such as media, files(TXT, CSS, JS, others) and move it to S3. S3 is a storage server which will deal with immediate storage & fetch of static content. 
  2. Make your front-end code production-ready, minify it and deploy it on S3 as a static web hosting. 
  3. Replace database server with a database service. AWS has a NoSQL database service called DynamoDB, which is a fast, scalable & secure and does not require any infrastructure setup. If we need a relational database, then AWS provides other DB services for relational database architecture. 
  4. AWS Lambda is the FaaS service which is trigger based. When a request is received from the user, the Lambda code will get executed. Our application code will reside in Lambda and the entire application is managed using it. So the next step is to convert our APIs into Lambda functions. 
  5. The request sent by the user will be consumed by AWS API gateway and forwarded to the respective lambda functions.

 

In the above entire process, the user will not have to set up the server. All the process of a typical server setup is handled by AWS services which can be configured in some clicks. That helps us set up a server easily and doesn't need any maintenance. However, internally AWS might create a server on their own to run their service but the user will not know what happens inside. AWS will take care of that. 

 

Moreover, we need to understand that not all the application cannot be moved to serverless architecture as complex operations, high-end computations might not work well with Serverless approach. Thus, before making any decision, you should identify whether the application requires high computation or just a number of fetch & write operations.

Let us know if you need any help deciding on the server or setting up the architecture!