@interlace/serverless

Getting Started

Install and configure @interlace serverless plugins in under 2 minutes.

Install

npm install --save-dev @interlace/serverless-api-gateway-caching @interlace/serverless-iam-roles-per-function @interlace/serverless-devkit
pnpm add -D @interlace/serverless-api-gateway-caching @interlace/serverless-iam-roles-per-function @interlace/serverless-devkit
yarn add -D @interlace/serverless-api-gateway-caching @interlace/serverless-iam-roles-per-function @interlace/serverless-devkit
bun add -d @interlace/serverless-api-gateway-caching @interlace/serverless-iam-roles-per-function @interlace/serverless-devkit

Quick Start

Add the plugin to your serverless.yml:

plugins:
  - '@interlace/serverless-api-gateway-caching'

custom:
  interlaceCaching:
    enabled: true
    clusterSize: '0.5'
    ttlInSeconds: 300
    flushOnDeploy: true

functions:
  getUser:
    handler: src/handler.get
    events:
      - http:
          path: /users/{id}
          method: get
          caching:
            enabled: true
            cacheKeyParameters:
              - name: request.path.id

Or use TypeScript

serverless.ts
import { defineConfig, defineFunction } from '@interlace/serverless-devkit';

export default defineConfig({
  service: 'my-api',
  provider: {
    name: 'aws',
    runtime: 'nodejs20.x',
    region: 'us-east-1',
  },
  plugins: ['@interlace/serverless-api-gateway-caching'],
  custom: {
    interlaceCaching: {
      enabled: true,
      clusterSize: '0.5',
      ttlInSeconds: 300,
    },
  },
  functions: {
    getUser: defineFunction({
      handler: 'src/handler.get',
      events: [
        {
          http: {
            path: '/users/{id}',
            method: 'get',
            caching: {
              enabled: true,
              cacheKeyParameters: [{ name: 'request.path.id' }],
            },
          },
        },
      ],
    }),
  },
});

Deploy

sls deploy --aws-profile interlace

Verify

sls caching status
# --- Cache Status ---
#   Enabled:  true
#   Size:     0.5 GB
#   Status:   AVAILABLE

What's next?

On this page