Socket
Book a DemoInstallSign in
Socket

@nexus-navigators/lambda-http-interceptor

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nexus-navigators/lambda-http-interceptor

A Node.js http interceptor to invoke Lambda functions

latest
Source
npmnpm
Version
1.2.3
Version published
Maintainers
0
Created
Source

@nexus-navigators/lambda-http-interceptor

Node.js http interceptor for Lambda HTTP APIs

npm version npm downloads npm version Continuous Integration codecov GitHub issues GitHub pull requests GitHub Repo stars GitHub forks

Intercept HTTP calls that are intended to hit a Lambda that resolves API Gateway requests. Use cases include unit tests, integration tests, or connecting directly to a Lambda while bypassing API Gateway.

Installation

npm i --save @nexus-navigators/lambda-http-interceptor

Usage


import { enable, clear, registerIntercept } from '@nexus-navigators/lambda-http-interceptor'

const handler = (event: APIGatewayProxyEventV2) => {
  console.log(event)
  return {
    status: 200,
    body: { out: 'OK' },
  }
}

enable()
registerIntercept({
  eventType: 'apiGatewayProxyV1',
  listenerType: 'handler',
  eventHandler: handler,
  hostMatch: /.*lambda-function\.com.*/,
  eventParams: {
    binaryTypes: [],
  },
  contextParams: {
    functionName: 'testFunction',
    timeout: 1,
  }
})

const response = await fetch('https://lambda-function.com/test')

assert.equal(response.status, 200)
const json = await response.json()
assert.equal(json.out, 'OK')

API

Register Options

OptionDescription
eventTypeThe type of event to be sent to the Lambda function. Can be apiGatewayProxyV1 or apiGatewayProxyV2.
listenerTypeThe type of listener to be used for invoking the Lambda function. Can be handler or sdk.
eventHandlerWhen listenerType is handler then a Lambda handler function must be provided
hostMatchA string or RegExp used to match hosts for requests. Can be blank if all HTTP requests should be sent to the function.
eventParamsAn object containing API Gateway parameters to be passed to the Lambda function.
contextParamsAn object containing Lambda context parameters to be passed to the Lambda function. Required when setting listenerType to handler

Event Parameters

ParameterDescription
binaryTypesAn array of binary types to be passed to the Lambda function. The interceptor will convert these kinds of requests to base64 and set the APIGateway event flag
authorizer (optional)Any authorization parameters that the API Gateway would have added to the event
pathParameters (optional)Any path parameters that the API Gateway would have added to the event
stageVariables (optional)Any query stage variables that the API Gateway would have added to the event
resource (optional)The resource value API gateway would have added to the event

Context Parameters

Context parameters are only used when listenerType is handler. These help fill out the context parameter when executing the handler.

ParameterDescription
functionName (required)The name of the Lambda function.
timeout (optional)The timeout for the Lambda function.
awsRequestId (optional)A requestID that is typically a UUID.
memoryLimitInMB (optional)The memory size for the Lambda function.
functionVersion (optional)The version of the Lambda function.
logStreamName (optional)A log stream name for CloudWatch Logs.
invokedFunctionArn (optional)The ARN for the function
clientContext (optional)Any clientContext that would be sent, matches ClientContext.
identity (optional)A CognitoIdentity object that would be set by Lambda.

Keywords

aws

FAQs

Package last updated on 10 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts