AWS Lambda: set 500ms timeouts on s3 requests to work around latency spikes.

This commit is contained in:
Brandon Liu
2022-11-23 10:38:03 +08:00
parent 0e8d051933
commit f9a4848684
3 changed files with 10 additions and 4 deletions

View File

@@ -8,7 +8,8 @@
"name": "pmtiles-aws",
"version": "0.0.0",
"dependencies": {
"@aws-sdk/client-s3": "^3.213.0"
"@aws-sdk/client-s3": "^3.213.0",
"@aws-sdk/node-http-handler": "^3.212.0"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.108",

View File

@@ -10,9 +10,10 @@
"private": true,
"scripts": {
"tsc": "tsc --noEmit --watch",
"build": "esbuild src/index.ts --target=es2020 --outfile=dist/index.mjs --format=esm --bundle --platform=node --target=node18 --external:@aws-sdk/client-s3 --banner:js=//$(git describe --always) && cd dist && zip lambda_function.zip index.mjs"
"build": "esbuild src/index.ts --target=es2020 --outfile=dist/index.mjs --format=esm --bundle --platform=node --target=node18 --external:@aws-sdk/client-s3 --external:@aws-sdk/node-http-handler --banner:js=//$(git describe --always) && cd dist && zip lambda_function.zip index.mjs"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.213.0"
"@aws-sdk/client-s3": "^3.213.0",
"@aws-sdk/node-http-handler": "^3.212.0"
}
}

View File

@@ -17,9 +17,13 @@ import https from "https";
import zlib from "zlib";
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
import { NodeHttpHandler } from "@aws-sdk/node-http-handler";
// the region should default to the same one as the function
const s3client = new S3Client({});
const s3client = new S3Client({requestHandler:new NodeHttpHandler({
connectionTimeout: 500,
socketTimeout: 500
})});
async function nativeDecompress(
buf: ArrayBuffer,