> ## Documentation Index
> Fetch the complete documentation index at: https://upstash-fix-issues-on-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

#  AWS Lambda

<Snippet file="redis/redisclientnote.mdx" />

### Database Setup

Create a Redis database using [Upstash Console](https://console.upstash.com) or
[Upstash CLI](https://github.com/upstash/cli). Select the same region with your
AWS Lambda to minimize the latency. Copy the `UPSTASH_REDIS_REST_URL` and
`UPSTASH_REDIS_REST_TOKEN` for the next steps.

### Project Setup

We will use
[Serverless Framework](https://www.serverless.com/framework/docs/getting-started)
but you can use AWS SAM or others.

Run `npx serverless` and select the `AWS - Node.js - HTTP API`

```shell
npx serverless

Creating a new serverless project

? What do you want to make? AWS - Node.js - HTTP API
? What do you want to call this project? aws-node-http-api-project

✔ Project successfully created in aws-node-http-api-project folder

? Do you want to login/register to Serverless Dashboard? No

? Do you want to deploy now? No

What next?
Run these commands in the project directory:

serverless deploy    Deploy changes
serverless info      View deployed endpoints and resources
serverless invoke    Invoke deployed functions
serverless --help    Discover more commands
```

Install dependencies:

```bash
cd aws-node-http-api-project
npm init -y
npm install @upstash/redis
```

### The Code

Update `handler.js` as below and replace `UPSTASH_REDIS_REST_URL` and
`UPSTASH_REDIS_REST_TOKEN`:

```js
const { Redis } = require("@upstash/redis/with-fetch");

module.exports.hello = async (event) => {
  const redis = new Redis({
    url: "UPSTASH_REDIS_REST_URL",
    token: "UPSTASH_REDIS_REST_TOKEN",
  });

  const data = await redis.incr("counter");
  return {
    statusCode: 200,
    body: JSON.stringify({
      view_count: data,
    }),
  };
};
```

### Deploy

Deploy your function with `npx serverless deploy`

The endpoint of the AWS Lambda function will be printed.

### Repo

[https://github.com/upstash/upstash-redis/tree/main/examples/aws-lambda](https://github.com/upstash/upstash-redis/tree/main/examples/aws-lambda)
