title: How can I zip Node Lambda dependencies in AWS CDK stack?
body: <p>I am using the CDK to create a simple serverless project with API Gateway, Lambda and DynamoDB. Seems pretty cool so far but I get the following error when I add an external dependency to the Lambda:</p>
  <pre><code>&quot;Runtime.ImportModuleError: Error: Cannot find module './uuid-random'&quot;,
  </code></pre>
  <p>For clarity, I'm not asking what the problem is with this error, as that is well documented. I'm looking for help as my attempts to zip the dependencies have failed so far.</p>
  <p>I have done my research, and I am not alone in this scenario. However, I'm a little confused with what path to take. I need to bundle my dependencies but all of the examples so far are fairly complex for what I am doing, and none of the examples fit. I have also seen suggestions of using <code>fromAsset</code>, but that didnt work either (cdk deploy just hung). So, I'd really appreciate any help in getting past this seemingly simple issue. TIA.</p>
  <p><strong>Project structure:</strong></p>
  <pre><code>bin/
    cdkProject.js
  handlers/
    api.js
  lib/
    cdkProject-stack.js
  node_modules/
  test/
  .gitignore
  cdk.json
  package.json
  tsconfig.json
  </code></pre>
  <p><strong>Lambda (api.js)</strong></p>
  <pre><code>const AWS = require(&quot;aws-sdk&quot;);
  const db = new AWS.DynamoDB;
  const TABLE_NAME = process.env.TABLE_NAME || &quot;&quot;;
  const PRIMARY_KEY = process.env.PRIMARY_KEY || &quot;&quot;;
  const uuid = require('./uuid-random');
  
  async function postProduct(event) {
  
    const params = {
      TableName: TABLE_NAME,
      Item: {
        &quot;id&quot;: {
          S: uuid()
        },
        &quot;name&quot;: {
          S: &quot;Test Product 1&quot;
        },
        &quot;price&quot;: {
          N: &quot;1.55&quot;
        },
        &quot;tags&quot;: {
          SS: [ &quot;tag1&quot;,&quot;tag2&quot; ] 
        } 
      }
    };
  
    try {
      const response = await db 
        .putItem(params)
        .promise()
        .then(res =&gt; res)
        .catch(err =&gt; err);
      console.log(JSON.stringify(response, undefined, 2));
      return JSON.stringify(response, undefined, 2)
    } catch (err) {
      console.log(JSON.stringify(err, undefined, 2));
    }
  }
  
  module.exports = {
    postProduct
  }
  </code></pre>