@smitejs/serverless
Serverless runtime adapters for Smite apps.
yarn add @smitejs/serverless12 documented symbols · version 2.0.0-SNAPSHOT.0 · source
AWS
typeApiGatewayHandler
type ApiGatewayHandler = (event: ApiGatewayV2Event, context?: unknown) => Promise<ApiGatewayResponse>;The AWS Lambda handler produced by lambdaify.
packages/serverless/src/aws.ts:41
interfaceApiGatewayResponse
interface ApiGatewayResponse {
readonly statusCode: number;
readonly headers: Readonly<Record<string, string>>;
readonly cookies?: readonly string[];
readonly body: string;
readonly isBase64Encoded: false;
}The API Gateway proxy response returned by lambdaify.
packages/serverless/src/aws.ts:28
interfaceApiGatewayV2Event
interface ApiGatewayV2Event {
readonly version?: string;
readonly rawPath?: string;
readonly path?: string;
readonly rawQueryString?: string;
readonly queryStringParameters?: Readonly<Record<string, string | undefined>>;
readonly headers?: Readonly<Record<string, string | undefined>>;
readonly cookies?: readonly string[];
readonly body?: string | null;
readonly isBase64Encoded?: boolean;
readonly requestContext?: {
readonly http?: {
readonly method?: string;
readonly path?: string;
};
};
}The subset of an API Gateway v2 event consumed by lambdaify.
packages/serverless/src/aws.ts:5
functionlambdaify
function lambdaify(app: AppDescriptor, options?: LambdaifyOptions): ApiGatewayHandler;Adapts a Smite app (or a single named router) to an AWS API Gateway v2 Lambda handler. When router is given, the handler only dispatches that router's routes, so each router becomes a genuinely separate Lambda. The returned handler closes over the scoped app; requests for other routers return 404.
const handler = lambdaify(app);200
{
id: "42",
q: "ada",
session: "abc",
}
"application/json; charset=utf-8",packages/serverless/src/aws.ts:136
interfaceLambdaifyOptions
interface LambdaifyOptions {
readonly router: string;
}Options for lambdaify: scope the handler to a single named router.
packages/serverless/src/aws.ts:126
Deployment
functionserverless
function serverless(options: ServerlessOptions): SmitePlugin;Creates a CLI plugin that emits serverless.yml and deploys it with the Serverless Framework. Other infrastructure tools can implement the same optional deployment hook without changing the Smite app or CLI. Pass plugins, resources, custom, or extend to declare Serverless Framework plugins and raw CloudFormation resources of any service without touching the generated document.
const plugin = serverless({
service: "orders-api",
outfile,
region: "us-east-1",
plugins: ["serverless-offline"],
custom: { offline: { httpPort: 4000 } },
resources: {
Resources: {
AssetsBucket: {
Type: "AWS::S3::Bucket",
Properties: { BucketName: "orders-static-assets" },
},
},
},
functions: {
api: { app: "orders", handler: "dist/handler.handler" },
},
});
await plugin.run({ apps: [app] });"service: orders-api"
"region: us-east-1"
"handler: dist/handler.handler"
"path: /orders/{id}"
"method: get"
"serverless-offline"
"httpPort: 4000"
"AWS::S3::Bucket"
"orders-static-assets"
"function"packages/serverless/src/plugin.ts:381
Reference
interfaceServerlessFunction
interface ServerlessFunction {
readonly handler: string;
readonly app?: string;
readonly events?: readonly ServerlessHttpEvent[];
}A function entry emitted into serverless.yml.
packages/serverless/src/plugin.ts:28
interfaceServerlessHttpEvent
interface ServerlessHttpEvent {
readonly path: string;
readonly method: string;
}A Serverless Framework HTTP API event.
packages/serverless/src/plugin.ts:22
interfaceServerlessOptions
interface ServerlessOptions {
readonly service: string;
readonly functions?: Readonly<Record<string, ServerlessFunction>>;
readonly outfile?: string;
readonly outdir?: string;
readonly handlerExport?: string;
readonly runtime?: string;
readonly region?: string;
readonly stage?: string;
readonly command?: string;
readonly plugins?: readonly ServerlessPluginEntry[];
readonly resources?: Readonly<Record<string, unknown>>;
readonly custom?: Readonly<Record<string, unknown>>;
readonly extend?: Readonly<Record<string, unknown>>;
}Options for the serverless deployment plugin.
packages/serverless/src/plugin.ts:51
typeServerlessPluginEntry
type ServerlessPluginEntry = string | ServerlessPluginReference;A Serverless Framework plugin declaration for the emitted plugins block.
packages/serverless/src/plugin.ts:48
interfaceServerlessPluginReference
interface ServerlessPluginReference {
readonly name?: string;
readonly localPath?: string;
readonly config?: Readonly<Record<string, unknown>>;
}A Serverless Framework plugin reference: an installed name or local path.
packages/serverless/src/plugin.ts:38
functionwriteServerlessConfig
function writeServerlessConfig(apps: readonly AppDescriptor[], options: ServerlessOptions, context?: ServerlessPluginContext): Promise<string>;Writes a Serverless Framework configuration for compiled Smite apps.