title: AWS - s3.listobjects suddenly returning Null data object with message "Type Error: cannot read property 'Contents' of null"
body: <p>In console I'm getting: </p>
  
  <blockquote>
    <p>.../aws-sdk/lib/request.js31 throw err;<br>
    "Type Error: cannot read property 'Contents' of null"</p>
  </blockquote>
  
  <p>The following snippet which <strong><em>was working perfectly for months</em></strong> has all of a sudden begun throwing an error when it tries to read the <code>data.Contents.length</code> properties into the <code>folderLength</code> variable.  </p>
  
  <p>I'm using <code>aws-sdk</code> for Node as well as Express4 and socket.io.</p>
  
  <p>All of my AWS credentials are appropriately situated in the .env file</p>
  
  <p>The userID variable is getting set correctly from elsewhere. (Checked with console.log)</p>
  
  <p>The real puzzler is that the app is working fine in the deployed version on Heroku but this problem only seems to be happening when I'm running it through locally.</p>
  
  <p>Any help would be much appreciated... </p>
  
  <pre><code>aws.config.update({accessKeyId: AWS_ACCESS_KEY, secretAccessKey: AWS_SECRET_KEY});
  
  var s3 = new aws.S3();
  // name the new AWS folder
  var folder = userID + "/";
  var s3_params = {
    Bucket: S3_BUCKET,  
    Key: folder, //+ req.query.file_name,   
    Expires: 60,
    ACL: 'public-read' 
  };
  
  s3.listObjects({Bucket: S3_BUCKET, Delimiter: '/', Prefix: folder}, function(err, data){
    var folderLength = data.Contents.length;
  
    //etc etc....
  });
  </code></pre>