Firsts impressions on the use of AWS Serverless
A serverless architecture is a way to build and run applications and services without having to manage infrastructure. All the management is done by AWS, so you no longer have to provision, scale, and maintain servers to run your applications, databases, and storage systems.
AWS has several services than can do all of that. The image below shows a basic architecture to develop serverless applications in AWS.
Amazon S3 is a file storage service which also provides a simple method for hosting static websites.
Amazon API Gateway allows to create and configure all the routes or endpoints for RESTful APIs. Each endpoint calls one or several lambda functions.
Amazon DynamoDB is a fully managed NoSQL database, it’s where all the data of the application is stored in this architecture.
There are different ways to configure the services we mentioned before. In this first contact with AWS, we used the Amazon console to configure the API Gateway endpoints, creating Lambda functions and database objects. One of the downsides is that it is probably not the fastest way to write your code. It works just fine at first, for a quick test maybe, but if we were working on a bigger, more complex app it would definitely take too much time. This is why we ended up using AWS Serverless Application Model (“SAM”).
SAM is a model to define serverless apps where you can define simplified syntax in order to express the configuration for all the resources described above. By using a SAM file you can bring up all the resources in less than a minute, which makes it a really powerful tool.
Some of the most relevant features of serverless apps are the possibility of running the whole app without provisioning or managing servers and the fact that the scalability is automatic.
Moreover, you only need to pay for the compute time you consume, which means that you won’t be charged if the Lambda code is not running.
Programming an API with this method is very different from doing the same with Express/Node.js. It might take some time to get used to it at first, as you need to define the entire infrastructure of the app in a SAM file, but then you quickly realize its great potential when it comes to creating an API. You will be saving an important amount of time on the maintenance of the infrastructure and on the code-typing part as well.
Deploying is quite fast with AWS CLI. However, we noticed that calls to endpoints triggering Lambda functions which access a DynamoDB take a bit longer than they would if we were working with a NodeJS server running 24 hours a day. However, the difference was negligible.
All in all, AWS serverless have proved to be a very interesting option that should be kept in mind for future projects.