Platforms

AWS Lambda

Running mion APIs on AWS Lambda for serverless deployments.

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

Installation

npm install @mionkit/aws @mionkit/router

Quick Start

import {initMionAws} from '@mionkit/aws';
import {routes} from './aws-routes.ts';

export const handler = initMionAws(routes);

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 {initMionAws} from '@mionkit/aws';
import {routes} from './aws-routes.ts';

export const handler = initMionAws(routes, {
    prefix: '/api', // API prefix
    // ... other router options
});
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>;
}