Skip to content
This repository has been archived by the owner on Jan 28, 2025. It is now read-only.

RFC S3 client revert #1021

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/libs/lambda-at-edge/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const LOCAL_EXTERNALS = [
"./manifest.json",
"./routes-manifest.json",
"./prerender-manifest.json",
"./images-manifest.json"
"./images-manifest.json",
"./s3-client.js"
];
const NPM_EXTERNALS = ["aws-lambda", "aws-sdk/clients/s3"];

Expand Down Expand Up @@ -47,5 +48,7 @@ export default [
{ filename: "api-handler", minify: false },
{ filename: "api-handler", minify: true },
{ filename: "image-handler", minify: false },
{ filename: "image-handler", minify: true }
{ filename: "image-handler", minify: true },
{ filename: "s3-client", minify: false },
{ filename: "s3-client", minify: true }
].map(generateConfig);
11 changes: 10 additions & 1 deletion packages/libs/lambda-at-edge/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ class Builder {
* @param shouldMinify
*/
async processAndCopyHandler(
handlerType: "api-handler" | "default-handler" | "image-handler",
handlerType:
| "api-handler"
| "default-handler"
| "image-handler"
| "s3-client",
destination: string,
shouldMinify: boolean
) {
Expand Down Expand Up @@ -298,6 +302,11 @@ class Builder {
join(this.outputDir, DEFAULT_LAMBDA_CODE_DIR, "index.js"),
!!this.buildOptions.minifyHandlers
),
this.processAndCopyHandler(
"s3-client",
join(this.outputDir, DEFAULT_LAMBDA_CODE_DIR, "s3-client.js"),
!!this.buildOptions.minifyHandlers
),
this.buildOptions?.handler
? fse.copy(
join(this.nextConfigDir, this.buildOptions.handler),
Expand Down
10 changes: 3 additions & 7 deletions packages/libs/lambda-at-edge/src/default-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ const handleOriginResponse = async ({
const bucketName = domainName.replace(`.s3.${region}.amazonaws.com`, "");

// Lazily import only S3Client to reduce init times until actually needed
const { S3Client } = await import("@aws-sdk/client-s3/S3Client");
const { S3Client } = require("./s3-client");

const s3 = new S3Client({
region: request.origin?.s3?.region,
Expand Down Expand Up @@ -675,9 +675,7 @@ const handleOriginResponse = async ({
ContentType: "text/html",
CacheControl: "public, max-age=0, s-maxage=2678400, must-revalidate"
};
const { PutObjectCommand } = await import(
"@aws-sdk/client-s3/commands/PutObjectCommand"
);
const { PutObjectCommand } = require("./s3-client");
await Promise.all([
s3.send(new PutObjectCommand(s3JsonParams)),
s3.send(new PutObjectCommand(s3HtmlParams))
Expand Down Expand Up @@ -742,9 +740,7 @@ const handleOriginResponse = async ({
body: html
};
} else {
const { GetObjectCommand } = await import(
"@aws-sdk/client-s3/commands/GetObjectCommand"
);
const { GetObjectCommand } = require("./s3-client");
// S3 Body is stream per: https://github.com/aws/aws-sdk-js-v3/issues/1096
const getStream = await import("get-stream");

Expand Down
9 changes: 9 additions & 0 deletions packages/libs/lambda-at-edge/src/s3-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { GetObjectCommand } from "@aws-sdk/client-s3/commands/GetObjectCommand";
import { PutObjectCommand } from "@aws-sdk/client-s3/commands/PutObjectCommand";
import { S3Client } from "@aws-sdk/client-s3/S3Client";

module.exports = {
GetObjectCommand,
PutObjectCommand,
S3Client
};
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ describe("Builder Tests (dynamic)", () => {
"manifest.json",
"pages",
"prerender-manifest.json",
"routes-manifest.json"
"routes-manifest.json",
"s3-client.js"
]);

// api pages should not be included in the default lambda
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ describe("Builder Tests (no API routes)", () => {
"manifest.json",
"pages",
"prerender-manifest.json",
"routes-manifest.json"
"routes-manifest.json",
"s3-client.js"
]);

// api pages should not be included in the default lambda
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ describe("Builder Tests (with locales)", () => {
"manifest.json",
"pages",
"prerender-manifest.json",
"routes-manifest.json"
"routes-manifest.json",
"s3-client.js"
]);

// api pages should not be included in the default lambda
Expand Down
4 changes: 3 additions & 1 deletion packages/libs/lambda-at-edge/tests/build/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ describe("Builder Tests", () => {
"manifest.json",
"pages",
"prerender-manifest.json",
"routes-manifest.json"
"routes-manifest.json",
"s3-client.js"
]);

// api pages should not be included in the default lambda
Expand Down Expand Up @@ -490,6 +491,7 @@ describe("Builder Tests", () => {
"pages",
"prerender-manifest.json",
"routes-manifest.json",
"s3-client.js",
"testFile.js"
]);

Expand Down
3 changes: 2 additions & 1 deletion packages/libs/lambda-at-edge/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"node_modules",
"./src/api-handler.ts",
"./src/default-handler.ts",
"./src/image-handler.ts"
"./src/image-handler.ts",
"./src/s3-client.ts"
]
}
7 changes: 6 additions & 1 deletion packages/libs/lambda-at-edge/tsconfig.bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@
"allowJs": true,
"resolveJsonModule": true
},
"include": ["./src/default-handler.ts", "./src/api-handler.ts", "./src/image-handler.ts"]
"include": [
"./src/default-handler.ts",
"./src/api-handler.ts",
"./src/image-handler.ts",
"./src/s3-client.ts"
]
}