Skip to main content

LambdaEdgeAdapter

@h4ad/serverless-adapter > LambdaEdgeAdapter

(class) LambdaEdgeAdapter

The adapter to handle requests from AWS Lambda @ Edge.

This adapter is not fully compatible with Lambda @ edge supported by @ vendia/serverless-express, the request body was modified to return NewLambdaEdgeBody instead OldLambdaEdgeBody . Also, the response has been modified to return entire body sent by the framework, in this form you MUST return the body from the framework in the format of . And when we get an error during the forwarding to the framework, we call resolver.fail instead of trying to return status 500 like the old implementation was.

Lambda edge docs Event Reference

Signature:

export declare class LambdaEdgeAdapter implements AdapterContract<CloudFrontRequestEvent, Context, CloudFrontRequestResult> 

Implements: AdapterContract <CloudFrontRequestEvent, Context, CloudFrontRequestResult>

Example

const getPathFromEvent = () => '/lambda/edge'; // will forward all requests to the same endpoint
const adapter = new LambdaEdgeAdapter(\{ getPathFromEvent });

(constructor)

Default constructor

Signature:

constructor(options?: LambdaEdgeAdapterOptions | undefined);

Parameters

ParameterTypeDescription
optionsLambdaEdgeAdapterOptions | undefined(Optional) The options to customize the LambdaEdgeAdapter

(property) cachedDisallowedHeaders

This property is used to cache the disallowed headers in RegExp version, even if you provide a string in disallowedHeader , we will cache it in an instance of RegExp .

Signature:

protected readonly cachedDisallowedHeaders: RegExp[];

(method) canHandle

Signature:

canHandle(event: unknown): event is CloudFrontRequestEvent;

Parameters

ParameterTypeDescription
eventunknown

Returns:

event is CloudFrontRequestEvent

(method) getAdapterName

Signature:

getAdapterName(): string;

Returns:

string

(method) getFlattenedHeadersFromCloudfrontRequest

Returns the headers with the flattened (non-list) values of the cloudfront request headers

Signature:

protected getFlattenedHeadersFromCloudfrontRequest(cloudFrontRequest: CloudFrontRequest): SingleValueHeaders;

Parameters

ParameterTypeDescription
cloudFrontRequestCloudFrontRequestThe cloudfront request

Returns:

SingleValueHeaders

(method) getHeadersForCloudfrontResponse

Returns headers in Cloudfront Response format.

Signature:

protected getHeadersForCloudfrontResponse(originalHeaders: BothValueHeaders): CloudFrontHeaders;

Parameters

ParameterTypeDescription
originalHeadersBothValueHeadersThe original version of the request sent by the framework

Returns:

CloudFrontHeaders

(method) getRequest

Signature:

getRequest(event: CloudFrontRequestEvent): AdapterRequest;

Parameters

ParameterTypeDescription
eventCloudFrontRequestEvent

Returns:

AdapterRequest

(method) getResponse

Signature:

getResponse(props: GetResponseAdapterProps<CloudFrontRequestEvent>): CloudFrontRequestResult;

Parameters

ParameterTypeDescription
propsGetResponseAdapterProps <CloudFrontRequestEvent>

Returns:

CloudFrontRequestResult

(method) getResponseToLambdaEdge

Returns the framework response in the format required by the Lambda @ edge.

Signature:

protected getResponseToLambdaEdge(\{ body, headers: frameworkHeaders, }: GetResponseAdapterProps<CloudFrontRequestEvent>): CloudFrontRequestResult;

Parameters

ParameterTypeDescription
{ body, headers: frameworkHeaders, }GetResponseAdapterProps <CloudFrontRequestEvent>

Returns:

CloudFrontRequestResult

(method) isEventTypeOrigin

Determines whether the event is from origin or is from viewer.

Signature:

protected isEventTypeOrigin(content: CloudFrontEvent['config']): boolean;

Parameters

ParameterTypeDescription
contentCloudFrontEvent['config']The event sent by AWS or the response sent by the framework

Returns:

boolean

(method) onErrorWhileForwarding

Signature:

onErrorWhileForwarding(\{ error, delegatedResolver, }: OnErrorProps<CloudFrontRequestEvent, CloudFrontRequestResult>): void;

Parameters

ParameterTypeDescription
{ error, delegatedResolver, }OnErrorProps <CloudFrontRequestEvent, CloudFrontRequestResult>

Returns:

void

(property) options

Signature:

protected readonly options?: LambdaEdgeAdapterOptions | undefined;

(method) shouldStripHeader

Returns the information if we should remove the response header

Signature:

protected shouldStripHeader(headerKey: string): boolean;

Parameters

ParameterTypeDescription
headerKeystringThe header that will be tested

Returns:

boolean