title: AWS "Hello World" Python Lambda results in Runtime.ImportModuleError: "Unable to import module"
body: <p>I've read dozens of articles, blog posts, docs, and Q&amp;A posts on this site on this issue, and I haven't found a solution.</p>
  <p>My Python code in <code>index.py</code> is simple:</p>
  <pre class="lang-py prettyprint-override"><code>def handler(event, context):
      print(&quot;hello world. this is hello handler&quot;)
  
  
  if __name__ == &quot;__main__&quot;:
      print(&quot;hello world. this is the main section in hello index.py&quot;)
  </code></pre>
  <p>Notice that I'm using the default filename <code>index.py</code> and the default entry point <code>handler</code>.</p>
  <p>I have a simple pyproject.toml:</p>
  <pre><code>[tool.poetry]
  name = &quot;hello&quot;
  version = &quot;0.1.0&quot;
  description = &quot;&quot;
  authors = []
  
  [tool.poetry.dependencies]
  python = &quot;~3.9&quot;
  
  [tool.poetry.dev-dependencies]
  
  [build-system]
  requires = [&quot;poetry-core&gt;=1.1.0&quot;]
  build-backend = &quot;poetry.core.masonry.api&quot;
  </code></pre>
  <p>As a basic sanity check, I can run the main section locally via:</p>
  <pre class="lang-sh prettyprint-override"><code>poetry run python index.py
  </code></pre>
  <p>I deploy via typescript CDK:</p>
  <pre class="lang-js prettyprint-override"><code>    const stack = new Stack(app, &quot;PythonHelloStack&quot;, {env})
      new PythonFunction(stack, `HelloFunction`, {
          runtime: Runtime.PYTHON_3_9,
          entry: path.join(__dirname, `../../../lambdas/hello`),
      })
  </code></pre>
  <p>This successfully creates the Lambda. When I run a test event against this, I get the error:</p>
  <pre><code>  &quot;errorMessage&quot;: &quot;Unable to import module 'index': No module named 'index'&quot;,
    &quot;errorType&quot;: &quot;Runtime.ImportModuleError&quot;,
  </code></pre>
  <p>To show a screenshot of the console, which shows the code:</p>
  <p><img src="https://i.stack.imgur.com/IuUfE.png" alt="screenshot of Lambda console" /></p>
  <p>The code shows up fine if I click on <code>index.py</code>. Why can't the AWS Lambda import <code>index.py</code>? I'm stuck on how to proceed in troubleshooting this.</p>