title: Nodejs Lambda, what the purpose of .promise()?
body: <p>promise() does in AWS lambda here.</p>
  
  <p>I want to send a signal immediately after the file is stored in s3. I'm wondering what .promise() does here. (--s3.putObject({}).promise()--)</p>
  
  <p>The timestamp of fetch(send_to_this_url) was observed at almost equal point when the file was seen on s3 storage. Based on this, promise() does not operate asynchronously. Am I getting something wrong here? </p>
  
  <p>Second in the first couple lines, response is returned when the response is ok. However, if it had returned earlier, file would have not been stored in s3, but it has been, so I am wondering what the purpose of the first if(response.ok) is supposed to be.</p>
  
  <p>Please share any ideas with me.!</p>
  
  <pre><code>
  fetch(url)
    .then((response) =&gt; {
      if (response.ok) {
        return response;
      }
      return Promise.reject(new Error(
            `Failed to fetch ${response.url}: ${response.status} ${response.statusText}`));
    })
    .then(response =&gt; response.buffer())
    .then((buffer) =&gt; {
  
        s3.putObject({
          ACL: "public-read",
          Bucket: process.env.BUCKET,
          Key: key,
          Body: buffer
        }).promise();   
  
        try{
          const send_to_this_url = "someurl?key=" + key;
          fetch(send_to_this_url);
        }catch(e){
          callback('error' + e.message);
        }
  
      }
    )
    .then(v =&gt; callback(null, v), callback);
  
  </code></pre>