title: How to install external modules in a Python Lambda Function created by AWS CDK?
body: <p>I'm using the Python AWS CDK in Cloud9 and I'm <strong>deploying a simple Lambda function</strong> that is supposed to <strong>send an API request</strong> to Atlassian's API <strong>when an Object is uploaded to an S3 Bucket</strong> (also created by the CDK). Here is my code for CDK Stack:</p>
  
  <pre class="lang-py prettyprint-override"><code>from aws_cdk import core
  from aws_cdk import aws_s3
  from aws_cdk import aws_lambda
  from aws_cdk.aws_lambda_event_sources import S3EventSource
  
  
  class JiraPythonStack(core.Stack):
      def __init__(self, scope: core.Construct, id: str, **kwargs) -&gt; None:
          super().__init__(scope, id, **kwargs)
  
          # The code that defines your stack goes here
          jira_bucket = aws_s3.Bucket(self,
                                      "JiraBucket",
                                      encryption=aws_s3.BucketEncryption.KMS)
  
          event_lambda = aws_lambda.Function(
              self,
              "JiraFileLambda",
              code=aws_lambda.Code.asset("lambda"),
              handler='JiraFileLambda.handler',
              runtime=aws_lambda.Runtime.PYTHON_3_6,
              function_name="JiraPythonFromCDK")
  
          event_lambda.add_event_source(
              S3EventSource(jira_bucket,
                            events=[aws_s3.EventType.OBJECT_CREATED]))
  
  </code></pre>
  
  <p>The lambda function code uses the <code>requests</code> module which I've imported. However, when I check the CloudWatch Logs, and test the lambda function - I get:</p>
  
  <p><strong>Unable to import module 'JiraFileLambda': No module named 'requests'</strong></p>
  
  <p><strong>My Question is: How do I install the requests module via the Python CDK?</strong></p>
  
  <p><a href="https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html" rel="noreferrer">I've already looked around online and found this</a>. But it seems to directly modify the lambda function, which would result in a Stack Drift (which I've been told is BAD for IaaS). I've also looked at the AWS CDK Docs too but didn't find any mention of external modules/libraries (I'm doing a thorough check for it now) Does anybody know how I can work around this?</p>
  
  <p><strong>Edit:</strong> <a href="https://github.com/aws/aws-cdk/issues/3660" rel="noreferrer">It would appear I'm not the only one looking for this</a>.</p>
  
  <p><a href="https://github.com/aws-samples/aws-cdk-examples/issues/130" rel="noreferrer">Here's another GitHub issue that's been raised.</a></p>