Built-in Key-Value Store

Almost every production cron job needs to remember information between runs — tracking the last processed ID, recording timestamps, or keeping counter states. LiteLambda includes a native, zero-setup Key-Value store injected directly into your script's execution context.

Why a Built-in KV Store?

On traditional serverless platforms like AWS Lambda or Cloudflare Workers, keeping state between scheduled invocations requires provisioning an external database (such as Amazon DynamoDB, Upstash Redis, or PostgreSQL). This adds connection overhead, IAM credentials, VPC networking complexities, and extra monthly bills.

With LiteLambda, every cron job automatically gets an isolated, persistent key-value store available via context.kv with no infrastructure to configure.

Quick Example: Incremental Data Sync

import requests

def handler(event, context):
    # 1. Retrieve the cursor from the previous execution
    last_id = context.kv.get("last_synced_id", default=0)
    print(f"Resuming sync from ID: {last_id}")

    # 2. Fetch new records created since that ID
    response = requests.get(f"https://api.example.com/orders?since_id={last_id}")
    orders = response.json().get("orders", [])

    for order in orders:
        process_order(order)

    # 3. Update the cursor if we processed any new orders
    if orders:
        new_last_id = orders[-1]["id"]
        context.kv.set("last_synced_id", new_last_id)
        print(f"Updated last_synced_id to: {new_last_id}")

    return {"processed": len(orders)}

API Reference

context.kv.get(key, default=None)

Retrieves a stored value by its string key. If the key does not exist, returns default (or None if not specified).

  • key (str): The key name (maximum 256 characters).
  • default (any, optional): The fallback value to return if the key does not exist.
# Example: Get with fallback
last_run = context.kv.get("last_run_at", default="never")
run_count = context.kv.get("total_runs", default=0)

context.kv.set(key, value)

Stores a JSON-serializable value under the specified key. Values can be strings, numbers, booleans, lists, or dictionaries.

  • key (str): The unique key name.
  • value (any JSON-serializable object): The data to persist. Maximum size is 64KB per value.
# Example: Saving primitives and structured objects
context.kv.set("total_runs", run_count + 1)
context.kv.set("user_metadata", {
    "status": "synced",
    "retries": 0,
    "tags": ["prod", "hourly"]
})

context.kv.delete(key)

Removes a key and its associated value from your cron job's store.

  • key (str): The key to delete. If the key does not exist, no error is thrown.
# Example: Clear temporary lock or flag
context.kv.delete("temporary_lock")

Limits & Quotas

Limit Value Description
Keys per job 100 keys Total active key-value pairs allowed per cron job
Max value size 64 KB Maximum JSON-serialized payload size per key
Key length 256 characters Max character length for key names

Viewing Stored Values in the Dashboard

You can inspect current stored key-value pairs directly in the LiteLambda dashboard:

  1. Navigate to your Cron Job's Edit screen.
  2. Click the Stored Values tab in the header.
  3. You'll see a live table of all persisted keys, their JSON values, and when each key was last modified.