mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 19:01:08 +00:00
AWS Lambda: port to node 18 and aws sdk v3
This commit is contained in:
2436
serverless/aws/package-lock.json
generated
2436
serverless/aws/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,9 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"tsc": "tsc --noEmit --watch",
|
||||
"build": "esbuild src/index.ts --target=es2020 --outfile=dist/index.js --format=cjs --bundle --platform=node --target=node16 --external:/var/runtime/node_modules/aws-sdk/clients/s3.js --banner:js=//$(git describe --always) && cd dist && zip lambda_function.zip index.js"
|
||||
"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"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.213.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,10 @@ import {
|
||||
import https from "https";
|
||||
import zlib from "zlib";
|
||||
|
||||
// @ts-ignore
|
||||
import s3client from "/var/runtime/node_modules/aws-sdk/clients/s3.js";
|
||||
|
||||
const keepAliveAgent = new https.Agent({ keepAlive: true, maxSockets: 1 });
|
||||
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
|
||||
|
||||
// the region should default to the same one as the function
|
||||
const s3 = new s3client({
|
||||
httpOptions: { agent: keepAliveAgent },
|
||||
});
|
||||
const s3client = new S3Client({});
|
||||
|
||||
async function nativeDecompress(
|
||||
buf: ArrayBuffer,
|
||||
@@ -95,15 +90,17 @@ class S3Source implements Source {
|
||||
}
|
||||
|
||||
async getBytes(offset: number, length: number): Promise<RangeResponse> {
|
||||
const resp = await s3
|
||||
.getObject({
|
||||
const resp = await s3client.send(
|
||||
new GetObjectCommand({
|
||||
Bucket: process.env.BUCKET!,
|
||||
Key: pmtiles_path(this.archive_name, process.env.PMTILES_PATH),
|
||||
Range: "bytes=" + offset + "-" + (offset + length - 1),
|
||||
})
|
||||
.promise();
|
||||
);
|
||||
|
||||
return { data: resp!.Body.buffer };
|
||||
const arr = await resp.Body!.transformToByteArray();
|
||||
|
||||
return { data: arr.buffer };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user