Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@anttiviljami/openapi-lambda-adapter

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@anttiviljami/openapi-lambda-adapter

JavaScript client library for integrating AWS Lambdas with openapi-client-axios

latest
npmnpm
Version
0.3.0
Version published
Maintainers
1
Created
Source

openapi-lambda-adapter

JavaScript/Typescript library for making AWS Lambda to Lambda calls via openapi-client-axios .

Features

  • Easy to make API like calls via openapi-client-axios library.
  client.api.registerRunner(getLambdaRunner('target-lambda-name'))
  • Use your API clients from OpenAPI v3 definitions to make AWS Lambda to Lambda calls between your platform microservices.
    • client.getPet(1)
    • client.searchPets()
    • client.searchPets({ ids: [1, 2, 3] })
    • client.updatePet(1, payload)
  • No need to run your requests via Api Gateway, you can directly run microservice to microservice call, i.e. AWS Lambda to Lambda, by leveraging AWS backbone infrastructure.
  • Leverage AWS IAM for permission management. Eg:
  Resources:
    MyLambda:
      Type: AWS::Serverless::Function
      Properties:
        ...
        Policies:
          - LambdaInvokePolicy:
              FunctionName: target-lambda-name

Restrictions

  • To run in AWS Lambda with Nodejs Runtime Environment >= 12

Quick Start

npm install --save openapi-client-axios openapi-lambda-adapter

Setup for single lambda handling all API Gateway requests

import OpenAPIClientAxios from 'openapi-client-axios';
import { getLambdaRunner } from 'openapi-lambda-adapter';

const api = new OpenAPIClientAxios({ definition: 'https://example.com/api/openapi.json' });
const client = api.initSync();
client.api.registerRunner(getLambdaRunner('target-lambda-name'));

const res = await client.createPet(null, { name: 'Garfield' });
console.log('Pet created', res.data);

Setup for multiple lambdas, each lambda handling one API Gateway resource

import OpenAPIClientAxios from 'openapi-client-axios';
import { getLambdaRunner } from 'openapi-lambda-adapter';

const api = new OpenAPIClientAxios({ definition: 'https://example.com/api/openapi.json' });
const client = api.initSync();
client.api.getOperations().forEach((operation) => {
    const lambdaName = ... get lambda-name for operationId
    client.api.registerRunner(getLambdaRunner(lambdaName), operation.operationId)
  })

const res = await client.createPet(null, { name: 'Garfield' });
console.log('Pet created', res.data);

const resp = await client.getPet({ id: 1 }, null);
console.log('Pet retrieved', resp.data);

Keywords

openapi

FAQs

Package last updated on 01 Mar 2023

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