Skip to content

Commit

Permalink
Changes Lambda@Edge Timeout to 30s
Browse files Browse the repository at this point in the history
  • Loading branch information
ofhouse committed Dec 21, 2020
1 parent a96367f commit 0045306
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions packages/proxy/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ function convertToCustomHeaders(
return cloudFrontHeaders;
}

// Timeout the connection before 5000ms to be able to print an error message
// https://stackoverflow.com/a/49857905/831465
function fetchTimeout(url: string, options?: RequestInit, timeout = 4800) {
// Timeout the connection before 30000ms to be able to print an error message
// See Lambda@Edge Limits for origin-request event here:
// https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-requirements-limits.html#lambda-requirements-see-limits
// Promise.race: https://stackoverflow.com/a/49857905/831465
function fetchTimeout(url: string, options?: RequestInit, timeout = 29500) {
return Promise.race([
fetch(url, options),
new Promise<never>((_, reject) =>
Expand Down
5 changes: 3 additions & 2 deletions test/lib/generateProxyModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ export async function generateProxySAM({
);
SAMTemplate.Resources[LambdaFunctionName] = {
Type: 'AWS::Serverless::Function',
// See resource limits for Lambda@Edge
// See resource limits for Lambda@Edge.
// We use Origin request event for the proxy
// https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-requirements-limits.html#lambda-requirements-see-limits
Properties: {
Handler: `${LambdaFunctionName}/handler.handler`,
Description: 'Lambda@Edge Proxy',
Runtime: 'nodejs12.x',
MemorySize: 128,
Timeout: 5,
Timeout: 30,
},
};

Expand Down

0 comments on commit 0045306

Please sign in to comment.