-
Notifications
You must be signed in to change notification settings - Fork 637
-
Hello,
I'm getting an Object.defineProperty called on non-object error when using any versions newer than 3.722.0 for my Lambda@Edge function. The full stack trace is:
"TypeError: Object.defineProperty called on non-object",
" at defineProperty (<anonymous>)",
" at __name (/var/task/origin-response.js:40:19710)",
" at <static_initializer> (/var/task/origin-response.js:40:26354)",
" at node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js (/var/task/origin-response.js:40:26300)",
" at /var/task/origin-response.js:1:554",
" at node_modules/@aws-sdk/client-s3/dist-cjs/index.js (/var/task/origin-response.js:58:70715)",
" at /var/task/origin-response.js:1:554",
" at Object.<anonymous> (/var/task/origin-response.js:58:426696)",
" at Module._compile (node:internal/modules/cjs/loader:1364:14)",
" at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)"
There doesn't seem any obviously relevant change on the next release, i.e. 3.723.0, hece posting this issue here.
A slightly simplified version of the code looks like this - it reads a file from a bucket and use the cotent as a custom response header value:
import { CloudFrontResponseEvent, CloudFrontResponse } from "aws-lambda";
import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3";
const s3 = new S3Client({
region: process.env.BUCKET_REGION,
});
const OBJECT = process.env.OBJECT;
const S3_BUCKET = process.env.S3_BUCKET;
export const handler = async (
event: CloudFrontResponseEvent
): Promise<CloudFrontResponse> => {
const response = event.Records[0].cf.response;
response.headers = response.headers || {};
let result = "";
}
try {
const params = { Bucket: S3_BUCKET, Key: OBJECT };
const s3Object = await s3.send(new GetObjectCommand(params));
if (!s3Object.Body) {
throw new Error("The file is empty or missing");
}
result += s3Object.Body.toString();
console.log("the file retrieved:", result);
response.headers["x-custom-header"] = [
{ key: "X-Custom-Header", value: result },
];
} catch (error) {
console.error("Error fetching the file or adding header:", error);
throw error;
}
return response;
};
Again, the same code works well if 3.722.0(or older) is used. Tested on the runtime Node v20 and 18, too, and no difference.
Can anyone shed some light on this.
Beta Was this translation helpful? Give feedback.
All reactions
Hey @crispy101 ,
I just found 2 resolved issues that might be related to this issue. What is your esbuild version? Have you tried to update esbuild version? It sounds like a version mismatch since it works fine with 3.722.0
Replies: 1 comment 1 reply
-
Hey @crispy101 ,
I just found 2 resolved issues that might be related to this issue. What is your esbuild version? Have you tried to update esbuild version? It sounds like a version mismatch since it works fine with 3.722.0
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi @zshzbh,
Wonderful! Yes that was the issue. Bumping up esbuild from 0.17 to 0.18 has resolved the issue.
Thanks very much!
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1 -
🎉 1 -
🚀 1