Skip to content

Instantly share code, notes, and snippets.

@digitalbase
Created April 23, 2020 19:47
Show Gist options
  • Save digitalbase/202b80bc3ea43fba2f42dc59ee98f012 to your computer and use it in GitHub Desktop.
Save digitalbase/202b80bc3ea43fba2f42dc59ee98f012 to your computer and use it in GitHub Desktop.
// /processPage.js
const extractor = require('./src/utils/event_extraction.util');
const referrer_detection = require('./src/utils/referrer_detection.util');
const { unmarshallNewImageEvent } = require('./src/utils/dynamo_stream.util');
const dynamoDBFactory = require('./src/dynamodb.factory');
const { SourceAttributionModel } = require('./src/models/SourceAttribution');
const dynamoDb = dynamoDBFactory();
const model = new SourceAttributionModel(dynamoDb);
module.exports.handler = async (event) => {
const eventData = event.Records[0];
if (eventData.eventName !== 'INSERT') {
return;
}
const eventAddedUnmarshalled = unmarshallNewImageEvent(eventData);
const extractedData = extractor(eventAddedUnmarshalled);
const {referrer, href } = extractedData;
const extraction = await referrer_detection(href, referrer);
if (!extraction) {
console.log('Skipping useless extraction', extractedData);
return;
}
try {
await model.store(eventAddedUnmarshalled, extraction);
} catch (e) {
console.log(e.message)
}
return eventData.eventName;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment