See Using AWS SAM, if you prefer AWS SAM
over Serverless Framework.
Step 1: Create database on Upstash
If you do not have one, create a database following this guide.Step 2: Project Setup
If you do not have it already install serverless framework via:npm install -g serverless
In any folder run serverless
as below:
This example uses ioredis, you can copy the connection string from the
Node tab in the console.
Step 3: Deploy Your Function
In the project folder run:serverless invoke -f hello
:
Test
button on the top right.

What can be the next?
- You can write and deploy another function to just get values from the database.
- You can integrate API Gateway so you can call your function via http.
- You can learn about how to monitor your functions from CloudWatch as described here.
Redis Connections in AWS Lambda
Although Redis connections are very lightweight, a new connection inside each Lambda function can cause a notable latency. On the other hand, reusing Redis connections inside the AWS Lambda functions has its own drawbacks. When AWS scales out Lambda functions, the number of open connections can rapidly increase. Fortunately, Upstash detects and terminates the idle and zombie connections thanks to its smart connection handling algorithm. Thanks to this algorithm; we have been recommending caching your Redis connection in serverless functions.See the blog post
about the database connections in serverless functions.