Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
srcBucket = body.source_bucket;
srcKey = body.source_key;
dstBucket = body.target_bucket;
dstKey = body.target_key;
correlationId = event.Records[0].messageAttributes.correlationId;
//.debug(correlationId);
} else {
// see https://stackoverflow.com/questions/41814750/how-to-know-event-souce-of-lambda-function-in-itself
// for other event sources
// Modify to suit your usecase
log.warn("Unexpected invocation");
log.warn(event);
return;
}
if (!srcKey.endsWith('doc') && !srcKey.endsWith('docx') ) {
log.warn('Unsupported file type ' + srcKey);
return; // TODO: if step function, return error?
}
if (srcKey.endsWith("/")) {
// assume this is a folder; event probably triggered by copy/pasting a folder
log.debug("is folder; returning");
return;
}
// Output input URL for ease of inspection
log.info("https://s3.console.aws.amazon.com/s3/object/" + srcBucket + "/" + srcKey);
srcKey = body.source_key;
dstBucket = body.target_bucket;
dstKey = body.target_key;
correlationId = event.Records[0].messageAttributes.correlationId;
//.debug(correlationId);
} else {
// see https://stackoverflow.com/questions/41814750/how-to-know-event-souce-of-lambda-function-in-itself
// for other event sources
// Modify to suit your usecase
log.warn("Unexpected invocation");
log.warn(event);
return;
}
if (!srcKey.endsWith('doc') && !srcKey.endsWith('docx') ) {
log.warn('Unsupported file type ' + srcKey);
return; // TODO: if step function, return error?
}
if (srcKey.endsWith("/")) {
// assume this is a folder; event probably triggered by copy/pasting a folder
log.debug("is folder; returning");
return;
}
// Output input URL for ease of inspection
log.info("https://s3.console.aws.amazon.com/s3/object/" + srcBucket + "/" + srcKey);
correlationId = event.Records[0].messageAttributes.correlationId;
//.debug(correlationId);
} else {
// see https://stackoverflow.com/questions/41814750/how-to-know-event-souce-of-lambda-function-in-itself
// for other event sources
// Modify to suit your usecase
log.warn("Unexpected invocation");
log.warn(event);
return;
}
if (!srcKey.endsWith('doc') && !srcKey.endsWith('docx') ) {
log.warn('Unsupported file type ' + srcKey);
return; // TODO: if step function, return error?
}
if (srcKey.endsWith("/")) {
// assume this is a folder; event probably triggered by copy/pasting a folder
log.debug("is folder; returning");
return;
}
// Output input URL for ease of inspection
log.info("https://s3.console.aws.amazon.com/s3/object/" + srcBucket + "/" + srcKey);
// Compute mimeType
var mimeType;
if (outputAs==Format.DOCX) {
mimeType = Format.DOC.toString();
dstBucket = event.target_bucket;
dstKey = event.target_key;
} else if (/* Lambda S3 trigger */ event.Records && event.Records[0].eventSource === 'aws:s3') {
//log.debug("received an S3 event");
//log.debug(event);
// Object key may have spaces or unicode non-ASCII characters.
srcBucket = event.Records[0].s3.bucket.name;
srcKey = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, " "));
// Avoid identity conversion, especially srcbucket == dstbucket
// where we'd cause an event loop
if (srcKey.endsWith('docx') && outputAs==Format.DOCX ) {
log.warn('Identity conversion avoided');
return;
}
// if dstBucket is undefined, we'll use source bucket.
dstBucket = process.env.S3_BUCKET_OUTPUT;
if (dstBucket === undefined) {
dstBucket = srcBucket;
}
// dstKey is computed below
if (outputAs==Format.DOCX) {
dstKey = srcKey + ".docx";
} else if (outputAs==Format.PDF) {
dstKey = srcKey + ".pdf";
} else {
log.error("Unsupported output format " + outputAs);
import * as log from "lambda-log";
const logMessage: log.LogMessage = log.log("customLevel", "custom", {
key: "value"
});
logMessage.level;
logMessage.meta;
logMessage.tags;
logMessage.msg;
logMessage.value;
logMessage.log;
logMessage.toJSON(true);
log.info("info", { key: "value" });
log.warn("warn", { key: "value" });
log.error(new Error("This is an error"), { key: "value" });
log.debug("debug", { key: "value" });
log.assert(true, "this will print");
const logInstance = new log.LambdaLog({
dynamicMeta: (logMessage: log.LogMessage) => {
return {
value: logMessage.value
};
}
});
logInstance.log("customLevel", "custom", { key: "value" });
logInstance.info("info", { key: "value" });
logInstance.warn("warn", { key: "value" });
logInstance.error(new Error("This is an error"), { key: "value" });
logInstance.debug("debug", { key: "value" });