Class: AwsLambdaAdapter
Class: AwsLambdaAdapter
AWS Lambda Adapter for Stone.js.
The AwsLambdaAdapter
provides seamless integration between Stone.js applications and the AWS Lambda environment. It processes incoming events from AWS Lambda, transforms them into IncomingEvent
instances, and returns a RawResponse
.
This adapter ensures compatibility with AWS Lambda's execution model and abstracts the event handling process for Stone.js developers.
Template
The type of the raw event received from AWS Lambda.
Template
The type of the response to send back to AWS Lambda.
Template
The AWS Lambda execution context type.
Template
The type of the processed incoming event.
Template
Options used to create an incoming event.
Template
The type of the outgoing response after processing.
Template
Context type specific to the adapter.
Example
import { AwsLambdaAdapter } from '@stone-js/aws-lambda-adapter';
const adapter = AwsLambdaAdapter.create({...});
const handler = await adapter.run();
export { handler };
See
Extends
Adapter
<AwsLambdaEvent
,RawResponse
,AwsLambdaContext
,IncomingEvent
,IncomingEventOptions
,OutgoingResponse
,AwsLambdaAdapterContext
>
Constructors
Constructor
protected new AwsLambdaAdapter(blueprint): AwsLambdaAdapter;
Create an Adapter.
Parameters
blueprint
IBlueprint
The blueprint to create the adapter.
Returns
AwsLambdaAdapter
Inherited from
Adapter<
AwsLambdaEvent,
RawResponse,
AwsLambdaContext,
IncomingEvent,
IncomingEventOptions,
OutgoingResponse,
AwsLambdaAdapterContext
>.constructor
Methods
eventListener()
protected eventListener(rawEvent, executionContext): Promise<RawResponse>;
Processes an incoming AWS Lambda event.
This method transforms the raw AWS Lambda event into a Stone.js IncomingEvent
, processes it through the pipeline, and generates a RawResponse
to send back.
Parameters
rawEvent
The raw AWS Lambda event to be processed.
executionContext
The AWS Lambda execution context for the event.
Returns
Promise
<RawResponse
>
A promise resolving to the processed RawResponse
.
onStart()
protected onStart(): Promise<void>;
Initializes the adapter and validates its execution context.
Ensures the adapter is running in an AWS Lambda environment. If not, it throws an error to prevent misuse.
Returns
Promise
<void
>
Throws
If executed outside an AWS Lambda context (e.g., browser).
run()
run<ExecutionResultType>(): Promise<ExecutionResultType>;
Executes the adapter and provides an AWS Lambda-compatible handler function.
The run
method initializes the adapter and returns a handler function that AWS Lambda can invoke. This handler processes events, manages context, and returns the appropriate response.
Type Parameters
ExecutionResultType
ExecutionResultType
= AwsLambdaEventHandlerFunction
The type representing the AWS Lambda event handler function.
Returns
Promise
<ExecutionResultType
>
A promise resolving to the AWS Lambda handler function.
Throws
If used outside the AWS Lambda environment.
Overrides
Adapter.run
create()
static create(blueprint): AwsLambdaAdapter;
Creates an instance of the AwsLambdaAdapter
.
Parameters
blueprint
IBlueprint
The application blueprint.
Returns
AwsLambdaAdapter
A new instance of AwsLambdaAdapter
.
Example
const adapter = AwsLambdaAdapter.create(blueprint);
await adapter.run();