Stacktape
Stacktape


Upstash Serverless Redis



Upstash provides a serverless Redis service, which allows you to use the fast, in-memory NoSQL data store without having to manage your own servers. With its per-request pricing and low latency, Upstash is a great choice for serverless applications.

Advantages

  • REST API: You can access your database using a simple REST API.
  • Secure: You can enable TLS with a single click.
  • Highly available: You can enable multi-zone replication to ensure that your data is always available.
  • Pay-per-request: You only pay for what you use. See the Upstash pricing for more details.
  • Scalable: Upstash automatically scales to meet your needs.

Disadvantages

  • Separate billing: Although Stacktape integrates with Upstash, you will still need to manage your billing separately.

Provider configuration

To use Upstash with Stacktape, you will need to:

  1. Create an Upstash account.
  2. Get your API key from the Upstash console.
  3. Store your credentials (the email address for your Upstash account and your API key) in a secret.
providerConfig:
upstash:
accountEmail: xxxxx.yyyy@example.com
apiKey: $Secret('upstash-api-key')
resources:
myUpstash:
type: upstash-redis

Basic usage

providerConfig:
upstash:
accountEmail: xxxxx.yyyy@example.com
apiKey: $Secret('upstash-api-key')
resources:
myUpstash:
type: upstash-redis
myFunction:
type: function
properties:
packaging:
type: stacktape-lambda-buildpack
properties:
entryfilePath: lambdas/upstash.ts
environment:
- name: UPSTASH_REDIS_REST_URL
value: $ResourceParam('myUpstash', 'restUrl')
- name: UPSTASH_REDIS_REST_TOKEN
value: $ResourceParam('myUpstash', 'restToken')
import upstash from '@upstash/redis';
const redis = upstash({ url: process.env.UPSTASH_REDIS_REST_URL, token: process.env.UPSTASH_REDIS_REST_TOKEN });
export default async (event) => {
// write data
let { data, error } = await redis.set('key1', 'value1');
// read data
({ data, error } = await redis.get('key1'));
console.log(data);
if (error) {
throw error;
}
};

The code for the myFunction function.

UpstashRedis  API reference
type
Required
properties.enableEviction
overrides

Deployment region

Upstash Redis is currently available in the following regions:

  • us-east-1
  • us-west-1
  • us-west-2
  • eu-west-1
  • eu-central-1
  • ap-southeast-1
  • ap-southeast-2
  • sa-east-1

If you deploy your stack in a different region, Stacktape will automatically deploy the database in the region that is geographically closest to your stack's region.

Enable eviction

When enabled, Redis will remove keys to free up memory for new data. It uses an eviction policy that prioritizes removing keys with an expiration set.

providerConfig:
upstash:
accountEmail: xxxxx.yyyy@example.com
apiKey: $Secret('upstash-api-key')
resources:
myUpstash:
type: upstash-redis
properties:
enableEviction: true

Referenceable parameters

The following parameters can be easily referenced using $ResourceParam directive directive.

To learn more about referencing parameters, refer to referencing parameters.

host
  • Hostname (address) of the Upstash Redis database.

  • Usage: $ResourceParam('<<resource-name>>', 'host')
port
  • Port of the Upstash Redis database.

  • Usage: $ResourceParam('<<resource-name>>', 'port')
password
  • Autogenerated password that can be used to authenticate towards the database.

  • Usage: $ResourceParam('<<resource-name>>', 'password')
restToken
  • Rest token which can be used when reading/writing from/to the database using the REST API

  • Usage: $ResourceParam('<<resource-name>>', 'restToken')
readOnlyRestToken
  • Rest token which can be used only for reading from the database using the REST API

  • Usage: $ResourceParam('<<resource-name>>', 'readOnlyRestToken')
restUrl
  • Rest URL which can be used when communicating with the database using the REST API

  • Usage: $ResourceParam('<<resource-name>>', 'restUrl')
redisUrl
  • Standard redis url (including password) which can be used for connecting using cli.

  • Usage: $ResourceParam('<<resource-name>>', 'redisUrl')

Contents