title: code build to create lambda layer - cannot find module
body: <p>I want package a lambda layer using codebuild.</p>
  
  <p>My codebuild buildspec is as follows:</p>
  
  <pre><code>version: 0.2
  
  phases:
    install:
      runtime-versions:
        nodejs: 10  
      commands:
        - npm init -y
        - npm install --save middy
  artifacts:
    files:
      - 'node_modules/**/*'
      - 'package-lock.json'
      - 'package.json'
  </code></pre>
  
  <p>This saves a <code>nodejs.zip</code> folder to my s3 bucket</p>
  
  <p>the resulting zip file looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/FbAED.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FbAED.png" alt="folder dir"></a></p>
  
  <p><a href="https://i.stack.imgur.com/34yAR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/34yAR.png" alt="middy is here"></a></p>
  
  <p>package.json is as follows:</p>
  
  <pre><code>{
    "name": "src",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
      "test": "echo \"Error: no test specified\" &amp;&amp; exit 1"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencies": {
      "middy": "^0.30.4"
    }
  }
  </code></pre>
  
  <p>however when I add this layer to my lambda (node10.x)</p>
  
  <p>and import my mods:</p>
  
  <pre><code>'use strict';
  var AWS = require('aws-sdk');
  const middy = require('middy')
  const { cors } = require('middy/middlewares')
  </code></pre>
  
  <p>Returns the following error:</p>
  
  <pre><code>{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module 'middy'\nRequire stack:\n- /var/task/function_code/verify_zipcode.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
    "trace": [
      "Runtime.ImportModuleError: Error: Cannot find module 'middy'",
      "Require stack:",
      "- /var/task/function_code/verify_zipcode.js",
      "- /var/runtime/UserFunction.js",
      "- /var/runtime/index.js",
      "    at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
      "    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
      "    at Object.&lt;anonymous&gt; (/var/runtime/index.js:43:30)",
      "    at Module._compile (internal/modules/cjs/loader.js:956:30)",
      "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)",
      "    at Module.load (internal/modules/cjs/loader.js:812:32)",
      "    at Function.Module._load (internal/modules/cjs/loader.js:724:14)",
      "    at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)",
      "    at internal/main/run_main_module.js:17:11"
    ]
  }
  </code></pre>
  
  <p>Adding the envoronment variable:
  <code>NODE_PATH : ./:/opt/node_modules</code> gave my lambda access to my layers, but lost the context of <code>aws-sdk</code></p>
  
  <p>After adding the env var I get the following error:</p>
  
  <pre><code>{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module 'aws-sdk'\nRequire stack:\n- /var/task/function_code/verify_zipcode.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
    "trace": [
      "Runtime.ImportModuleError: Error: Cannot find module 'aws-sdk'",
      "Require stack:",
      "- /var/task/function_code/verify_zipcode.js",
      "- /var/runtime/UserFunction.js",
      "- /var/runtime/index.js",
      "    at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
      "    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
      "    at Object.&lt;anonymous&gt; (/var/runtime/index.js:43:30)",
      "    at Module._compile (internal/modules/cjs/loader.js:956:30)",
      "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)",
      "    at Module.load (internal/modules/cjs/loader.js:812:32)",
      "    at Function.Module._load (internal/modules/cjs/loader.js:724:14)",
      "    at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)",
      "    at internal/main/run_main_module.js:17:11"
    ]
  }
  </code></pre>
  
  <p><strong>Is there a way to use both the native <code>aws-sdk</code> and my layers? Or do I need to use an <code>aws-sdk</code> layer anytime I use other custom layers?</strong></p>