Files
rentall-app/lambdas/imageProcessor/test-local.js
jackiettran 5d3c124d3e text changes
2026-01-21 19:20:07 -05:00

61 lines
1.3 KiB
JavaScript

/**
* Local testing script for the image processor lambda.
*
* Usage:
* npm run local -- <stagingKey> [bucket]
*
* Example:
* npm run local -- staging/items/test-image.jpg my-bucket
*
*/
const { handler } = require("./index");
async function main() {
// Filter out dotenv config args from process.argv
const args = process.argv
.slice(2)
.filter((arg) => !arg.startsWith("dotenv_config_path"));
// Get staging key from command line args
const stagingKey = args[0] || "staging/items/test-image.jpg";
const bucket = args[1] || process.env.S3_BUCKET;
console.log("Testing image processor lambda locally...");
console.log(`Bucket: ${bucket}`);
console.log(`Staging Key: ${stagingKey}`);
console.log("---");
// Simulate S3 event
const event = {
Records: [
{
eventSource: "aws:s3",
eventName: "ObjectCreated:Put",
s3: {
bucket: {
name: bucket,
},
object: {
key: stagingKey,
},
},
},
],
};
console.log("Event:", JSON.stringify(event, null, 2));
console.log("---");
try {
const result = await handler(event);
console.log("Result:", JSON.stringify(result, null, 2));
process.exit(0);
} catch (error) {
console.error("Error:", error);
process.exit(1);
}
}
main();