title: Loading a json file into DynamoDB
body: <p>This javaScript code works great when I execute it with Node using a local file, but now when I run this at the command line I get "Undefined:1".</p>
  
  <pre><code>var AWS = require('aws-sdk');
  const http = require("http");
  
  AWS.config.update({ region: "us-east-1" });
  
  //cron(0 18 ? * MON-FRI *)
  var docClient = new AWS.DynamoDB.DocumentClient();
  
  console.log("Importing Work Orders into DynamoDB Jobs table. Please wait.");
  
  http.get('http://www.MyWebSite.com/Data/WOjson/02152018.json', (res) =&gt; {
    const { statusCode } = res;
    const contentType = res.headers['content-type'];
  
    let error;
    if (statusCode !== 200) {
      error = new Error('Request Failed.\n' +
                        `Status Code: ${statusCode}`);
    } else if (!/^application\/json/.test(contentType)) {
      error = new Error('Invalid content-type.\n' +
                        `Expected application/json but received ${contentType}`);
    }
    if (error) {
      console.error(error.message);
      // consume response data to free up memory
      res.resume();
      return;
    }
  
  console.log("Now it is time to parse the file.");
  
    res.setEncoding('utf8');
    let rawData = '';
  
  res.on('data', (chunk) =&gt; { rawData += chunk; });
  res.on('end', () =&gt; {
    });
  const parsedData = JSON.parse(rawData);
  
  parsedData.forEach(function(job) {
      var params = {
          TableName: "Jobs",
          Item: {
              "userId":  job.userId,
              "WorkOrder": job.WorkOrder,
              "ServiceDate":  job.ServiceDate,
              "JobType": job.JobType
          }
      };
  
  // Here is where I post to the DynamoDB table
      docClient.put(params, function(err, data) {
         if (err) {
             console.error("Unable to add job", job.WorkOrder, ". Error JSON:", JSON.stringify(err, null, 2));
         } else {
             console.log("PutItem succeeded:", job.WorkOrder);
         }
      });
  });
  
  
  }).on('error', (e) =&gt; {
    console.error(`Got error: ${e.message}`);
  });
  </code></pre>
  
  <p><strong>I have updated the code to use http.</strong>  I do get the console log message, "Now it is time to parse the file.", but then I get the message "Undefined:1" and no items go into my DynamoDB table.</p>
  
  <pre><code>res.on('data', (chunk) =&gt; { rawData += chunk; });
  res.on('end', () =&gt; {
    });
  const parsedData = JSON.parse(rawData);
  
  parsedData.forEach(function(job) {
  </code></pre>
  
  <p>Ideally, I'd like to execute this lambda function on a schedule (once a day at say 6pm) to read a remote file into my DynamoDB table.</p>