Catalog npm
Back to packageRELEASE DETAILS

1.0.4

npm

@0to10/aws-api-gateway-handler

Typescript library for setting up Lambda functions to serve as API Gateway handler

api gatewayawsexpresslambda
Published14 Aug 2024
Direct dependencies22
Transitive dependenciesNot calculated

README

Current package documentation

AWS API Gateway Handler

This repository provides a bootstrapper when creating Node.js Lambda functions, to be used as API Gateway handlers.

Getting started

Get started quickly by following the instructions below.

Installation

Use NPM to install this library into your project:

npm install --save @0to10/aws-api-gateway-handler

Setup

Quick setup:

'use strict';

import http from 'http';

import {Application, Request, Response} from '@0to10/aws-api-gateway-handler';

const application: Application = new Application();

// Any application logic, such as registering routes, may be added after instantiation
application.express.get('/test', (
    _request: Request,
    response: Response,
): void => {
    response.status(200).json({
        message: 'Test was a success!',
    });
});

application.listen(80);

// Expose the handler
export const handler = application.handler.bind(application);

Configuration

You may optionally pass in configuration options to the constructor of the Application class, as follows:

import {Application, Configuration} from '@0to10/aws-api-gateway-handler';

const config: Configuration = {
    disable: [
        'x-powered-by',
        'etag',
    ],
    cors: false,
};

const application: Application = new Application(config);

Below is an overview of the configuration options available.

OptionTypeDefault
disablestring[]['x-powered-by']
corsbooleantrue

A full list of available features that may be disabled (via the disable option) is available on the Express.js website.

Events

Various events are emitted within this library, you may attach listeners to the events by following the example below:

// Application bootstrap omitted

application.events.on('listening', (port: number): void => {
    console.log('Listening on port ' + port);
});

Below is an overview of the available events.

EventArgumentsNotes
listening(port: number)Emitted when the server is ready to process requests
event(event: APIGatewayProxyEvent)Emitted every time a request is handled
debug:error(error: any)Emitted whenever the error handler handles an error

AWS Cognito

This library exposes a cognito object on the Request object of Express to make Cognito user data easily accessible. See the type below.

type CognitoRequestInformation = {
    identityId?: string;
    userPoolId?: string;
    username?: string;
}

Note that request.cognito will always be an object, but any of the values may be undefined.

// Application bootstrap omitted

application.express.get('/test', (
    request: express.Request,
    _response: express.Response,
): void => {
    console.info('Cognito user:', {
        cognitoIdentityId: request.cognito.identityId,
        cognitoUserPoolId: request.cognito.userPoolId,
        cognitoUsername: request.cognito.username,
    });
});

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 22

Native requirements
22 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
express
Environment
{
  "local_name": "express",
  "alias": false,
  "peer_metadata": null
}
^4.18.2runtime
express-async-errors
Environment
{
  "local_name": "express-async-errors",
  "alias": false,
  "peer_metadata": null
}
^3.1.1runtime
aws-serverless-express
Environment
{
  "local_name": "aws-serverless-express",
  "alias": false,
  "peer_metadata": null
}
^3.4.0runtime
jest
Environment
{
  "local_name": "jest",
  "alias": false,
  "peer_metadata": null
}
^29.5.0development
tslib
Environment
{
  "local_name": "tslib",
  "alias": false,
  "peer_metadata": null
}
^2.2.0development
eslint
Environment
{
  "local_name": "eslint",
  "alias": false,
  "peer_metadata": null
}
^8.56.0development
ts-jest
Environment
{
  "local_name": "ts-jest",
  "alias": false,
  "peer_metadata": null
}
^29.1.0development
webpack
Environment
{
  "local_name": "webpack",
  "alias": false,
  "peer_metadata": null
}
^5.91.0development
supertest
Environment
{
  "local_name": "supertest",
  "alias": false,
  "peer_metadata": null
}
^7.0.0development
ts-loader
Environment
{
  "local_name": "ts-loader",
  "alias": false,
  "peer_metadata": null
}
^9.5.1development
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
~18.17.19development
webpack-cli
Environment
{
  "local_name": "webpack-cli",
  "alias": false,
  "peer_metadata": null
}
^5.1.4development
@jest/globals
Environment
{
  "local_name": "@jest/globals",
  "alias": false,
  "peer_metadata": null
}
^29.5.0development
@types/express
Environment
{
  "local_name": "@types/express",
  "alias": false,
  "peer_metadata": null
}
^4.17.21development
@types/type-is
Environment
{
  "local_name": "@types/type-is",
  "alias": false,
  "peer_metadata": null
}
^1.6.6development
@types/supertest
Environment
{
  "local_name": "@types/supertest",
  "alias": false,
  "peer_metadata": null
}
^6.0.2development
@types/aws-lambda
Environment
{
  "local_name": "@types/aws-lambda",
  "alias": false,
  "peer_metadata": null
}
~8.10.122development
@typescript-eslint/parser
Environment
{
  "local_name": "@typescript-eslint/parser",
  "alias": false,
  "peer_metadata": null
}
^6.19.0development
eslint-plugin-deprecation
Environment
{
  "local_name": "eslint-plugin-deprecation",
  "alias": false,
  "peer_metadata": null
}
^2.0.0development
license-checker-rseidelsohn
Environment
{
  "local_name": "license-checker-rseidelsohn",
  "alias": false,
  "peer_metadata": null
}
^4.3.0development
@types/aws-serverless-express
Environment
{
  "local_name": "@types/aws-serverless-express",
  "alias": false,
  "peer_metadata": null
}
~3.3.6development
@typescript-eslint/eslint-plugin
Environment
{
  "local_name": "@typescript-eslint/eslint-plugin",
  "alias": false,
  "peer_metadata": null
}
^6.19.0development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "813be8c97e5381161487385f60d2e174af510c26",
  "tarball": "https://registry.npmjs.org/@0to10/aws-api-gateway-handler/-/aws-api-gateway-handler-1.0.4.tgz",
  "fileCount": 87,
  "integrity": "sha512-+SDILIuowxq3CaPtdebTTKjRJ9OBpF8ihpeKbmBCNDMmRXwilnrCwUfIXvPMsD7qGwyuKmCY8tPl8oNWSrH3hw==",
  "signatures": [
    {
      "sig": "MEUCID5rScrOWZUzFLQ4NCSXThb3+BmIuYwgHiF0L70n+6FtAiEAoO7WMqHCO0WaxUFU82Pk8dXZm0/3Jsf293oRzdc3kkc=",
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
    }
  ],
  "unpackedSize": 64169
}

Repository

PENDING
0to10/aws-api-gateway-handler-library-ts

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:16 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:73fafedb6b9a2c8c4d092e7eec74c96be90302938475b87cb72f5dbfc30cc73f

Other collected versions

1.3.026 Jun1.2.15 May1.2.020 Feb1.1.016 Sept1.0.812 Sept1.0.716 AugView all collected versions →