Node.js, Lambda, Serverless and some cloud functions - the perfect mix for building a scalable app that’s easy to manage and doesn’t have many vulnerable dependencies. Also, it’s not expensive at all. Find out more about how much money you can save in our introduction to this technological combo.
Lambda is like the brain of the node-Lambda-Serverless organism. It allows you to encapsulate complicated project features within a computing platform and runs them only when a specific event is triggered. Lambda functions carry out the whole Amazon Web Services magic: beautiful documentation with clear examples, scalable features, cloud storing, image recognition, and a lot more!
Serverless is a cloud computing framework. It comes with a service that allows you to develop and deploy your AWS Lambda functions, along with the AWS infrastructure resources they require. It could be used to accomplish jobs via composed Lambda functions.
At Netguru, we use AWS often. The most frequent use case are features such as s3 storage and RDS as database services, CloudWatch with whole Management Tools for fast and clear application monitoring, and, of course, Amazon ES (Elasticsearch service).
We will use the following simple setup from Serverless’ main page with node.js as our backend:
We need a feature for resizing images, e.g. changing image width to 100px. We want to delegate it to a fast and scalable service, which will only be used when a certain event is triggered. With the setup steps above, we configured a boilerplate for our resizing logic. Now we can just use imagemagick, a node.js package with a resize function. And that’s it!
The biggest pros of this solution:
We’ve created a simple Lambda function for resizing images by sending them via the AWS gateway. Our project has received a new low-cost Lambda micro-service.
Now we want to add the feature for storing images in S3, the AWS database, and in return, we want to receive a link to the resized picture stored in the DB. This will take two additional steps:
S3 costs vary by region, but in our example, we choose the EU (London) region. The pricing for will be somewhere in the region of the following:
By now, our project has expanded its functionality and kept its complexity by transferring the s3-image function to the Serverless-Lambda feature.
Now it’s time to expand the project’s functionality with image recognition and save the results in a non-relational database. Recognition is a relatively new cloud-computing technology, but AWS offers a dedicated service for it. All we need to do is connect our Serverless-Lambda with the new services.
Once again, we’ve expanded the project’s functionality by using only the AWS SDK for Node.js. This example shows that a project doesn’t need to be bloated and unwieldy to have complex functionalities. In one lightweight Lambda function, we were able to contain the logic for uploading, processing (recognition) and receiving image data. All server logic remained in Amazon’s capable hands.
The last thing – pricing. Our project will be charged for processing images. We will need to pay $1 for 1,000 images, if we process up to one million of images each month. As the volume of images grows, this cost will be decreasing.
Without overly complicating our lives, we’ve solved many problems and complexity dependencies only by using our Node.js, Lambda and Serverless mix. We have everything in one place now, and we will be ready whenever users come up with new ideas.
There is no limit to connecting AWS modules together by using Serverless and Lambda. That’s the real power of Lambda functions. We recommend that you get rid of all excessive complications from your code and use the winning combination of Lambda, Serverless and cloud. This will improve your project’s features and performance, and save you a lot of headaches.