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
Parameter | Type | Description |
---|---|---|
options | LambdaEdgeAdapterOptions | 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
Parameter | Type | Description |
---|---|---|
event | unknown |
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
Parameter | Type | Description |
---|---|---|
cloudFrontRequest | CloudFrontRequest | The cloudfront request |
Returns:
(method) getHeadersForCloudfrontResponse
Returns headers in Cloudfront Response format.
Signature:
protected getHeadersForCloudfrontResponse(originalHeaders: BothValueHeaders): CloudFrontHeaders;
Parameters
Parameter | Type | Description |
---|---|---|
originalHeaders | BothValueHeaders | The original version of the request sent by the framework |
Returns:
CloudFrontHeaders
(method) getRequest
Signature:
getRequest(event: CloudFrontRequestEvent): AdapterRequest;
Parameters
Parameter | Type | Description |
---|---|---|
event | CloudFrontRequestEvent |
Returns:
(method) getResponse
Signature:
getResponse(props: GetResponseAdapterProps<CloudFrontRequestEvent>): CloudFrontRequestResult;
Parameters
Parameter | Type | Description |
---|---|---|
props | GetResponseAdapterProps <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
Parameter | Type | Description |
---|---|---|
{ 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
Parameter | Type | Description |
---|---|---|
content | CloudFrontEvent['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
Parameter | Type | Description |
---|---|---|
{ 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
Parameter | Type | Description |
---|---|---|
headerKey | string | The header that will be tested |
Returns:
boolean