lambda-compression
TypeScript icon, indicating that this package has built-in type declarations

0.2.11 • Public • Published

npm version

Lambda HTTP Payload Compression

This library provides a wrapper that can be used to compress content in responses when using the AWS HTTP API.

The library supports compression with br, gzip and deflate. It will return responses with compressed data matching the supported accept-encoding header provided by the client.

Installation

Simply add the lambda-compression package to your project:

npm add lambda-compression

# when using Yarn
yarn add lambda-compression

Usage

This library provides only one method compress that accepts two parameters with the respective types of APIGatewayProxyEventV2 and APIGatewayProxyStructuredResultV2 (for more details on these types, see TypeScript Types for AWS Lambda).

Simply call the compress method as follows before returning the result of your Lambda.

import { compress } from 'lambda-compression';

import {
  Handler,
  APIGatewayProxyEventV2,
  APIGatewayProxyResultV2,
} from 'aws-lambda';

type ProxyHandler = Handler<APIGatewayProxyEventV2, APIGatewayProxyResultV2>;

export const handler: ProxyHandler = async (event, context) => {
  return compress(event, {
    statusCode: 201,
    headers: {
      'Content-Type': 'application/json',
    },
    body: '{"data":"hello"}',
  });
};

Also See

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.2.117latest

Version History

VersionDownloads (Last 7 Days)Published
0.2.117
0.2.1037
0.2.84
0.2.70
0.2.60
0.2.50
0.2.40
0.2.30
0.2.20
0.2.10
0.2.00
0.1.30
0.1.20
0.1.10

Package Sidebar

Install

npm i lambda-compression

Weekly Downloads

48

Version

0.2.11

License

MIT

Unpacked Size

7.36 kB

Total Files

6

Last publish

Collaborators

  • mxro