title: Download multiple images from URL and upload to aws s3 from aws lambda (nodejs)
body: <p>I can use this code to upload a <strong>single</strong> image to s3. When I try multiple, only the first item is uploaded and lambda stops executing. I'm new to javascript so I don't understand the problem here.</p>
  <pre><code>async function downloadImage(url) {
    var options = {
          uri: url,
          encoding: null
      };
    await new Promise((resolve, reject) =&gt; {
      request(options, function(error, response, body) {
          if (error || response.statusCode !== 200) { 
              console.log(&quot;failed to get image&quot;);
              console.log(error);
          } else {
              s3.putObject({
                  Body: body,
                  Key: 'template/'+url.split('/').pop(),
                  Bucket: bucketName
              }, function(error, data) { 
                  if (error) {
                      console.log(&quot;error downloading image to s3&quot;);
                  } else {
                      console.log(&quot;success uploading to s3&quot;);
                  }
              }); 
          }   
      });
    })
    .catch((error) =&gt; {
      console.log(&quot;error&quot;);
    });
  }
  
  exports.handler = async (event, _ctx, _cb) =&gt; {
    var images = {
      banner: &quot;http://media.com/strip.png&quot;,
      icon: &quot;http://media.com/icon.png&quot;,
      logo: &quot;http://media.com/logo.png&quot;
    }
    
    for (const [key, value] of Object.entries(images)) {
      console.log(`${key}: ${value}`);
      await downloadImage(value);
    }
  }
  </code></pre>
  <p>The output I get from lambda for this:</p>
  <pre><code>2020-10-03T19:11:32.293Z    3cd401a6-08c6-49a2-b01c-99d6430ffc1a    INFO    banner: http://media.com/circle/strip.png
  2020-10-03T19:11:33.201Z    3cd401a6-08c6-49a2-b01c-99d6430ffc1a    INFO    success uploading to s3
  </code></pre>