5 ways to use serverless lambda function.

Serverless can be cool so here’s some ways I’ve used lambda function for in past.. you don’t always need to use it plus there’s an overhead involved but here we go..

First one if processing large files..
Imagine a big media file sitting in S3 bucket in need of processing (Decoding/encoding/cutting/removing portions/trimming etc.., anything!)

You’d be tempted to process it on the main server but that’d end up taking resources away from other more important things.

A better idea might be to process it via a lambda function so other critical services on main server aren’t affected.

Whenever a file is uploaded to S3 you could automatically invoke Lambda function which would take the responsibility of processing it.

Acting as a middlemen
Ever had a situation where you needed to make countless HTTP API calls to gather large amount of data but didn’t want to do it on your main server? HTTP calls are heavy and if you’re not clever about them they will affect your overall server.

You could create a single API gateway endpoint and tie it to a lambda function.

Then trigger this endpoint from your main application, this endpoint would trigger lambda function and make HTTP calls as necessary. In the end it would return/store the data from within lambda function.

Query result processing
SQL itself is amazing and fast but big database means you’re going to need to perform multiple iterations of cleansing.

For example, organizing data in a format for other application to consume. This process isn’t always quick.

You can simply offload this to lambda function which would then cleanup and return the data doing the heavy processing for you. You could even perform half the work on your main server and offload other half to lambda by sending it data in POST.

Notification listener endpoint
Lambda if tired to API gateway can also act as a listener, listening to services like payment gateway callbacks.

Whenever the endpoint is triggered, lambda can take over further processing whether it’d be storing data into RDS or notifying some other endpoint/service.

As simple as it sounds lambda can also be used to issue bearer token in response to correct user credentials.

Leave a comment

Your email address will not be published. Required fields are marked *