title: BluebirdJS bind() in AWS Lambda
body: <p>I'm having some weird behavior in a node.js AWS lambda function. In my local environment, I'm using bluebirdjs to handle my promises. I originally was "promisifying" the aws-sdk myself but later found this article <a href="https://aws.amazon.com/blogs/developer/support-for-promises-in-the-sdk/" rel="nofollow noreferrer">https://aws.amazon.com/blogs/developer/support-for-promises-in-the-sdk/</a> and converted it to use the "promise versions" of the aws-sdk methods. </p>
  
  <p>Basically, my problem comes in when I try to use the bind method of bluebird (<a href="http://bluebirdjs.com/docs/api/promise.bind.html" rel="nofollow noreferrer">http://bluebirdjs.com/docs/api/promise.bind.html</a>) to pass data through the promise chain. This works on my local environment and in my tests. When I deploy to lambda, however, I always get an error saying "stack: 'TypeError: Cannot set property \'property\' of undefined\n" which seems to me like "this" in the promise.then() callback is not defined. Does anyone have any clue as to why .bind() would work on my local machine and not in AWS Lambda? I'm running the same version of node.</p>
  
  <p>Here's what I'm doing</p>
  
  <pre><code>let s3getObjectPromise = s3.getObject({Bucket: bucket, Key: file}).promise();
  s3getObjectPromise
      .bind({})
      .then((data) =&gt; {
          this.test = 'test';
          return parsePOICSV(data, type)
      })
      .then(function(recordsToUpdate) {
          let test = this.test; // THROWS ERROR
          // pass recordsToUpdate down the promise chain
          let searchRequests = elasticSearchService.constructQuery(recordsToUpdate);
          return elasticSearchService.search(searchRequests, recordsToUpdate);
      })
  </code></pre>