Giter Club home page Giter Club logo

openapi-lambda-adapter's Introduction

openapi-lambda-adapter

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

Features

  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);

openapi-lambda-adapter's People

Contributors

idanielbot avatar

Stargazers

Roman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.