Skip to content

Repository files navigation

openapi-lambda-adapter

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

Versioning

0.x to 1.x

  • changed to AWS SDK v3 to reduce bundle size and allow the update to the Node 18 runtime

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::FunctionProperties:
...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

importOpenAPIClientAxiosfrom'openapi-client-axios';import{getLambdaRunner}from'openapi-lambda-adapter';constapi=newOpenAPIClientAxios({definition: 'https://example.com/api/openapi.json'});constclient=api.initSync();client.api.registerRunner(getLambdaRunner('target-lambda-name'));constres=awaitclient.createPet(null,{name: 'Garfield'});console.log('Pet created',res.data);

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

importOpenAPIClientAxiosfrom'openapi-client-axios';import{getLambdaRunner}from'openapi-lambda-adapter';constapi=newOpenAPIClientAxios({definition: 'https://example.com/api/openapi.json'});constclient=api.initSync();client.api.getOperations().forEach((operation)=>{constlambdaName= ... getlambda-nameforoperationIdclient.api.registerRunner(getLambdaRunner(lambdaName),operation.operationId)})constres=awaitclient.createPet(null,{name: 'Garfield'});console.log('Pet created',res.data);constresp=awaitclient.getPet({id: 1},null);console.log('Pet retrieved',resp.data);

About

Run AWS Lambda to Lambda requests with openapi-client-axios

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages