This example uses Redis clients. If you expect many concurrent AWS Lambda
invocation then we recommend using
upstash-redis which is HTTP/REST
based.
This example uses ioredis, you can copy the connection string from the
Node tab in the console.
Create Function
button.

Node.js 14.x
as runtime. Click
Create Function
.
Now you are on the function screen, scroll below to Function Code
section. On
Code entry type
selection, select Upload a .zip file
. Upload the app.zip
file you have just created and click on the Save
button on the top-right. You
need to see your code as below:

Test
button on the top right. Create
an event like the below:

- You can write and deploy another function to just get values from the database.
- You can learn better ways to deploy your functions such as serverless framework and AWS SAM
- 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. Since this algorithm is used; we have been recommending caching your Redis connection in serverless functions.See the blog post
about the database connections in serverless functions.
Client | #Commands | Issued Commands |
---|---|---|
redis-cli | 2 | AUTH - COMMAND |
node-redis | 3 | AUTH - INFO - QUIT |
ioredis | 3 | AUTH - INFO - QUIT |
redis-py | 1 | AUTH |
jedis | 2 | AUTH - QUIT |
lettuce | 2 | AUTH - QUIT |
go-redis | 1 | AUTH |