Platforms

AWS Lambda

Running mion APIs on AWS Lambda for serverless deployments.

mion can run on AWS Lambda for serverless deployments. The @mionjs/platform-aws package provides a handler compatible with API Gateway events.

Installation

npm install @mionjs/platform-aws @mionjs/router

Quick Start

import {createAwsLambdaHandler} from '@mionjs/platform-aws';
import {initMionRouter} from '@mionjs/router';
import {routes} from './aws-routes.ts';

await initMionRouter(routes);

export const handler = createAwsLambdaHandler();

API Gateway Configuration

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+}'

Configuration

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({});
For optimal cold start performance, keep your Lambda function dependencies minimal and use Lambda layers for shared code.

Type Reference

AwsLambdaOptions

export interface AwsLambdaOptions {
    /** Set of default response header to add to every response*/
    defaultResponseHeaders: Record<string, string>;
}