Platforms
AWS Lambda
Running mion APIs on AWS Lambda for serverless deployments.
@mionjs/platform-aws provides a Lambda handler for API Gateway events.
Installing the Adapter
npm install @mionjs/platform-aws @mionjs/router
Creating the Handler
import {createAwsLambdaHandler} from '@mionjs/platform-aws';
import './aws-routes.ts';
export const handler = createAwsLambdaHandler();
import {createMionRouter, Routes} from '@mionjs/router';
const mion = createMionRouter();
const routes = {
sayHello: mion.route((ctx, name: string): string => {
return `Hello ${name}!`;
}),
} satisfies Routes;
// the server entry only imports this file
export const myApi = mion.initRoutes(routes);
export type MyApi = typeof myApi;
API Gateway Configuration
mion works with both REST API and HTTP API (v2). Configure a catch-all route:
# serverless.yml example
functions:
api:
handler: src/handler.handler
events:
- httpApi:
method: '*'
path: '/{proxy+}'
When API Gateway or a Lambda Function URL sends a base64 body (
isBase64Encoded: true, common with binary media types), the handler decodes it first. maxBodySize measures the decoded text.Adapter Options
Pass options such as maxBodySize (128 KB by default) and maxBodySizeCap to createAwsLambdaHandler. maxBodySizeCap defaults to the 6 MB AWS allows on a synchronous invocation; override it when your entry path differs (1 MB behind an Application Load Balancer). Set router options like basePath once in createMionRouter, and see Request Size for body limits.
import {createAwsLambdaHandler} from '@mionjs/platform-aws';
import './aws-routes.ts';
export const handler = createAwsLambdaHandler({});
For faster cold starts, keep dependencies minimal and use Lambda layers for shared code.