title: Is it good to move s3 initialisation out of lambda handler?
body: <p>In AWS lambda context, I am just wondering if it is good practice to move the S3 client creation out of the handler, and what benefits or performance improvement it can get?</p>
  <p>For the following two examples,</p>
  <p>Will the later one (with s3 object creation out of handler) benefit from sharing keep-alive connections across invocations. And the later one also provides connection pool?</p>
  <p>Thank you,
  Ron</p>
  <pre class="lang-js prettyprint-override"><code>import { S3 } from 'aws-sdk';
  export const handleEvent: SQSHandler = async (event: SQSEvent, context: Context) =&gt; {
    const s3Client = S3();
    s3Client.getObject(...);
    s3Client.putObject(...);
  }
  </code></pre>
  <p>Vs.</p>
  <pre class="lang-js prettyprint-override"><code>import { S3 } from 'aws-sdk';
  
  const s3Client = S3(); // move the S3 object creation out of handler
  
  export const handleEvent: SQSHandler = async (event: SQSEvent, context: Context) =&gt; {
    s3Client.getObject(...);
    s3Client.putObject(...);
  }
  </code></pre>