Skip to main content
tip

Don't know what a resolver is? See the Architecture section.

The best and most agnostic resolver (for sure) is using callback, generally every serverless environment supports callback as the third argument of the handler.

When the handler is created with getHandler, it will return void and the cloud will wait until the event loop is empty. This happens when your framework sends the response and the adapter transforms the response the way your cloud can handle, at this point the response will be passed to the callback and then the event loop will be empty.

You can use this resolver with any cloud, with any framework or any adapter.

AWS

To use this resolver on AWS, you MUST leave callbackWaitsForEmptyEventLoop as true, otherwise, AWS will not wait for this resolver to resolve.

Usage

To use, you can import and call the method setResolver, as per the code below:

index.ts
import { ServerlessAdapter } from '@h4ad/serverless-adapter';
import { CallbackResolver } from '@h4ad/serverless-adapter/resolvers/callback';

const express = require('express');

const app = express();
export const handler = ServerlessAdapter.new(app)
.setResolver(new CallbackResolver())
// continue to set the other options here.
//.setFramework(new ExpressFramework())
//.setHandler(new DefaultHandler())
//.addAdapter(new AlbAdapter())
//.addAdapter(new SQSAdapter())
//.addAdapter(new SNSAdapter())
// after put all methods necessary, just call the build method.
.build();
tip

To know more about how AWS deals with callback handlers, see NodeJS Handler section.