/*jshint esversion: 6 */
'use strict';
const AWS = require("aws-sdk");
const dynamodb = new AWS.DynamoDB.DocumentClient();
const geoip = require('geoip-lite');

function makeId() {
  let text = '';
  const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

  for (var i = 0; i < 64; i++)
    text += possible.charAt(Math.floor(Math.random() * possible.length));

  return text;
}

exports.handler = (event, context, callback) => {
  const ip = event.sourceIP.split(',', 1)[0]
  console.log('Looking up IP ' + ip)
  const geo = geoip.lookup(ip);
  console.log('Location is ' + geo.ll)
  let id = makeId();
  const currentTime = Math.floor(new Date() / 1000);
  const currentTimePlusTwentyFourHours = (Math.floor(new Date() / 1000)) + 86400;

  const params = {
    TableName: 'impact-map',
    Item: {
      'Id': id,
      'Added': currentTime,
      'Expire': currentTimePlusTwentyFourHours,
      'Coordinates': geo.ll,
      'Action': event.action
    },
  };

  // Creates the item
  dynamodb.put(params, function(err, data) {
    if (err) {
      console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2)); // Handles error in console.
      callback('Entry was not successful');
    } else {
      console.log("Added item:", JSON.stringify(data, null, 2));
      callback(null, 'Added item');
    }
  });
};

@@ -36,40 +36,8 @@
 t';%0A
-const AWS = require(%22aws-sdk%22);%0A
 cons
@@ -120,16 +120,114 @@
 -lite');
+%0Aconst AWSXRay = require('aws-xray-sdk-core');%0Aconst AWS = AWSXRay.captureAWS(require('aws-sdk'));
 %0A%0Afuncti

Add x-ray calls