Created
April 23, 2020 19:30
-
-
Save digitalbase/5bcd271de503729b207a6bd1a5ccdbb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { unmarshallNewImageEvent } = require('./src/utils/dynamo_stream.util'); | |
| const dynamoDBFactory = require('./src/dynamodb.factory'); | |
| const { UserToAnonymousModel } = require('./src/models/UserToAnonymous'); | |
| const dynamoDb = dynamoDBFactory(); | |
| const model = new UserToAnonymousModel(dynamoDb); | |
| module.exports.handler = async (event) => { | |
| const eventData = event.Records[0]; | |
| const eventAddedUnmarshalled = unmarshallNewImageEvent(eventData); | |
| const { type: eventType, userId, anonymousId } = eventAddedUnmarshalled; | |
| // only handle dynamo INSERTS and events with type identify | |
| if (eventData.eventName !== 'INSERT' || eventType !== 'identify') { | |
| return; | |
| } | |
| try { | |
| await model.storeMap(userId, anonymousId); | |
| } 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