Stone.jsDocs
Paradigm

Adapters

AWS Lambda

AWS Lambda has its own event shape, so it gets its own adapter, in two flavours: an HTTP adapter for API Gateway and Function URLs, and a generic adapter for everything else Lambda delivers (queues, schedules, custom events).

#HTTP on Lambda

For a web API behind API Gateway or a Function URL, use @stone-js/aws-lambda-http-adapter. Your routes work unchanged; the adapter maps the Lambda HTTP event to an intention and the response back.

terminalbash
npm i @stone-js/aws-lambda-http-adapter
app/Application.tsdeclarativeimperative
import { StoneApp } from '@stone-js/core'
import { Routing } from '@stone-js/router'
import { AwsLambdaHttp } from '@stone-js/aws-lambda-http-adapter'

@AwsLambdaHttp()   // API Gateway / Function URL HTTP events
@Routing()
@StoneApp({ name: 'tasks' })
export class Application {}
import { defineStoneApp } from '@stone-js/core'
import { routerBlueprint } from '@stone-js/router'
import { awsLambdaHttpAdapterBlueprint } from '@stone-js/aws-lambda-http-adapter'

export const App = defineStoneApp(
  { name: 'tasks' },
  [routerBlueprint, awsLambdaHttpAdapterBlueprint]
)

#Generic (non-HTTP) invocations

For events that are not HTTP, a queue message, a scheduled trigger, a custom payload, use the generic @stone-js/aws-lambda-adapter with @AwsLambda(). The same handler contract applies; the intention just carries the event's payload.

app/Application.tsts
import { AwsLambda } from '@stone-js/aws-lambda-adapter'

@AwsLambda()
@StoneApp({ name: 'workers' })
export class Application {}

#Which one

PackageTypeDescription
@stone-js/aws-lambda-http-adapter@AwsLambdaHttpAPI Gateway / Function URL HTTP events. Use with @Routing.
@stone-js/aws-lambda-adapter@AwsLambdaGeneric Lambda invocations (queues, schedules, custom).

#Deploy

stone build produces the handler bundle in dist/; point your IaC at it. Here it is with AWS SAM: an HTTP API in front of the function, whose Handleris the built server file exporting the adapter handler. The ephemeral per-event container matches Lambda's execution model exactly, so there is nothing long-lived to warm.

terminalbash
npm run build            # -> dist/ (handler bundle)
sam deploy --guided
template.yamlyaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Resources:
  Api:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: dist/                 # the stone build output
      Handler: server.handler        # built entry (e.g. dist/server.mjs) exporting the handler
      Runtime: nodejs20.x
      Architectures: [arm64]
      MemorySize: 256
      Timeout: 15
      Environment:
        Variables:
          NODE_ENV: production
      Events:
        HttpApi:
          Type: HttpApi              # API Gateway HTTP API -> @AwsLambdaHttp
          Properties: { Path: /{proxy+}, Method: ANY }

Stone.js

Your app exists in every runtime. Until you run it.

An open-source project by Stone Foundation
Created by Mr. Stone (Evens Pierre)