60 lines
1.4 KiB
JavaScript
60 lines
1.4 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
|
|
*
|
|
* Note: Requires .env.dev file with DATABASE_URL and AWS credentials configured.
|
|
*/
|
|
|
|
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();
|