mion can run on AWS Lambda for serverless deployments. The @mionkit/aws package provides a handler compatible with API Gateway events.
npm install @mionkit/aws @mionkit/router
import {initMionAws} from '@mionkit/aws';
import {routes} from './aws-routes.ts';
export const handler = initMionAws(routes);
import {Routes, route} from '@mionkit/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 {initMionAws} from '@mionkit/aws';
import {routes} from './aws-routes.ts';
export const handler = initMionAws(routes, {
prefix: '/api', // API prefix
// ... other router options
});
export interface AwsLambdaOptions {
/** Set of default response header to add to every response*/
defaultResponseHeaders: Record<string, string>;
}