View on GitHub

lambda-middleware

A collection of middleware for AWS lambda functions.

@lambda-middleware/http-header-normalizer

npm version downloads open issues debug build status codecov dependency status devDependency status

Middleware for AWS lambdas that normalizes headers to lower-case and referer to referrer and vice-versa. If you are used to the corresponding middy middleware, please note that this middleware acts differently as it does not hold an exception list and converts everything to lower-case.

Lambda middleware

This middleware is part of the lambda middleware series. It can be used independently.

Usage

import { httpHeaderNormalizer } from "@lambda-middleware/http-header-normalizer";
import { APIGatewayProxyEvent, APIGatewayProxyResult } from "aws-lambda";

// This is your AWS handler
async function helloWorld({
  headers,
}: APIGatewayProxyEvent): APIGatewayProxyResult {
  return {
    body: JSON.stringify({
      msg: headers["custom-header"],
    }),
    statusCode: 200,
  };
}

// Wrap the handler with the middleware
export const handler = httpHeaderNormalizer()(helloWorld);