mion can run on AWS Lambda for serverless deployments. The @mionjs/platform-aws package provides a handler compatible with API Gateway events.
npm install @mionjs/platform-aws @mionjs/router
import {createAwsLambdaHandler} from '@mionjs/platform-aws';
import {initMionRouter} from '@mionjs/router';
import {routes} from './aws-routes.ts';
await initMionRouter(routes);
export const handler = createAwsLambdaHandler();
import {Routes, route} from '@mionjs/router';
export const routes = {
sayHello: route((ctx, name: string): string => {
return `Hello ${name}!`;
}),
} satisfies Routes;
mion works with both REST API and HTTP API (v2) in API Gateway. Make sure to configure a catch-all route:
# serverless.yml example
functions:
api:
handler: src/handler.handler
events:
- httpApi:
method: '*'
path: '/{proxy+}'
You can pass configuration options to initMionAws:
import {createAwsLambdaHandler} from '@mionjs/platform-aws';
import {initMionRouter} from '@mionjs/router';
import {routes} from './aws-routes.ts';
await initMionRouter(routes, {
basePath: 'api', // API prefix
});
export const handler = createAwsLambdaHandler({});
export interface AwsLambdaOptions {
/** Set of default response header to add to every response*/
defaultResponseHeaders: Record<string, string>;
}