title: Converting a Node 14.X program into an AWS Node 12.X Lambda function
body: <p><strong>My Goal</strong></p>
  <p>Take a node program (a command-line server-side program, not a web application) and deploy it as a lambda function in AWS.</p>
  <p><strong>Background: my node development environment/approach</strong></p>
  <ul>
  <li>Node 14.X on my MacBook Pro: version 14.2.0, in which ECMAScript module support is on by default</li>
  <li>Developing my software as ES6 modules as follows:
  <ul>
  <li>Putting type: module in my package.json file</li>
  <li>Using the .js extension rather than .mjs and .cjs extensions (because VS Code intellisense does not play nice with the multi-extension approach )</li>
  <li>As this is a back-end program, I am not doing any transpiration or bundling (currently no Babel or Webpack)</li>
  </ul>
  </li>
  </ul>
  <p><strong>Creating the lambda function</strong></p>
  <ul>
  <li>Using latest node env supported by AWS (12.X)</li>
  <li>From what I can tell in the AWS lambda environment:
  <ul>
  <li>The entry point is hard-coded in this case (index.js)
  <ul>
  <li>There’s no way for me to pass command line arguments to node</li>
  </ul>
  </li>
  <li>If I try to run my code unchanged (with type: module), it fails as expected, because AWS node is trying to ‘require’ my ES6 module:
  <ul>
  <li>“Must use import to load ES Module: /var/task/index.js\nrequire() of ES modules is not supported. Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove &quot;type&quot;: &quot;module&quot; from /var/task/package.json.”</li>
  </ul>
  </li>
  <li>If I try to change extensions on files to be explicit, AWS gags because it hard-codes the entry point to be ‘index.js’</li>
  <li>If I naively remove the type:module from package.json, it fails as expected because it wants everything to be CommonJS:
  <ul>
  <li>“SyntaxError: Cannot use import statement outside a module&quot;</li>
  </ul>
  </li>
  </ul>
  </li>
  </ul>
  <p><strong>Where I need help</strong></p>
  <p>From a couple hours of reading/research I’ve done, it seems like these are my options??:</p>
  <ol>
  <li>Rewrite my code to use CommonJS (undesirable, I want to use the modern features/approach)</li>
  <li>Set up either babel or a bundler like WebPack to convert my ES6 modules into CommonJS, and dump the converted code into the lambda</li>
  <li>Use ‘esm’</li>
  </ol>
  <p><strong>My Questions</strong></p>
  <ol>
  <li>Am I correct to be going ‘all in’ on modules in my own code?</li>
  <li>Which approach above: #1, #2, #3 — or something else — is the easiest path to success here and the ‘proper’ approach?</li>
  </ol>
  <p>Thank you!</p>