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'))
Resources:
MyLambda:
Type: AWS::Serverless::Function
Properties:
...
Policies:
- LambdaInvokePolicy:
FunctionName: target-lambda-name
Restrictions
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);