Do More on AWS With Timescale Cloud: Build an Application Using Lambda Functions in Python
AWS Lambda is a serverless compute service that allows you to run code in the cloud with ease. A common misconception is that the name “serverless” implies no servers are involved, which couldn’t be further from the truth.
When you deploy your application (in this video, we build a time-series application with two Lambda functions in Python), there are, in fact, servers running your code—you just don’t need to worry about it like you would if you deployed your application on EC2. This is where AWS shines: it abstracts the infrastructure, operating system, logging, and much more away, freeing up time for you to work on what actually matters: your application code.
Another great benefit of this abstraction is scaling. Usually, scaling an application involves a framework like Kubernetes, which is complex and expensive to run. AWS Lambda, on the other hand, can run multiple concurrent instances of your code out of the box. This might require some clever architecting with locks for specific transactional workloads but shouldn’t be necessary in most cases.
Those properties of AWS Lambda make it a perfect candidate for time-series applications which tend to process high volumes of data. Whether you deploy your Lambda function behind an API Gateway or as a Kinesis data stream consumer, it will seamlessly scale up and down depending on the quantity of data flowing in. Lambda can even scale to zero, meaning that if no data is being received, you are not paying for expensive servers running idle.
This is not the first time I’ve experimented with pairing AWS and Timescale Cloud. Recently, I posted a video on how to set up VPC peering between your own AWS VPC and your Timescale Cloud VPC so you can make your valuable time-series data less vulnerable to exploits and attacks.
I also explored the possibilities of popular AWS services and Timescale Cloud a few months ago when I co-wrote a blog post about using them to build simpler and faster time-series applications.
This time, I created a serverless time-series application comprising two Lambda functions written in Python. One function parses a post request and inserts the request parameters into TimescaleDB on Timescale Cloud. The other retrieves the latest five entries in our database. In the video, I use the AWS SAM CLI to provision the AWS infrastructure that powers our application.
Check it out! I hope you enjoy it.