title: using boto3 in a python3 virtual env in AWS Lambda
body: <p>I am trying to use <strong>Python3.4</strong> and <strong>boto3</strong> to walk an <strong>S3</strong> bucket and publish some file locations to an <strong>RDS</strong> instance.  The part of this effort I am having trouble with is when using boto3.  My lambda function looks like the following:</p>
  
  <pre><code>import subprocess
  
  def lambda_handler(event, context):
      args = ("venv/bin/python3.4", "run.py")
      popen = subprocess.Popen(args, stdout=subprocess.PIPE)
      popen.wait()
      output = popen.stdout.read()
      print(output)
  </code></pre>
  
  <p>and, in my <strong>run.py</strong> file I have some lines:</p>
  
  <pre><code>import boto3
  
  s3c = boto3.client('s3')
  </code></pre>
  
  <p>which cause an exception.  The <strong>run.py</strong> file is not relevant for this question however, so in order make this post more concise, I've found that the cause of this error is generated with executing the lambda function:</p>
  
  <pre><code>import subprocess
  
  def lambda_handler(event, context):
      args = ("python3.4", "-c", "import boto3; print(boto3.client('s3'))")
      popen = subprocess.Popen(args, stdout=subprocess.PIPE)
      popen.wait()
      output = popen.stdout.read()
      print(output)
  </code></pre>
  
  <p>My logstream reports the error:</p>
  
  <pre><code>Event Data
  START RequestId: 2b65421a-664d-11e6-81db-974c7c09d283 Version: $LATEST 
  Traceback (most recent call last): 
   File "&lt;string&gt;", line 1, in &lt;module&gt; 
   File "/var/runtime/boto3/__init__.py", line 79, in client 
   return _get_default_session().client(*args, **kwargs) 
   File "/var/runtime/boto3/session.py", line 250, in client 
   aws_session_token=aws_session_token, config=config) 
   File "/var/runtime/botocore/session.py", line 818, in create_client 
   client_config=config, api_version=api_version) 
   File "/var/runtime/botocore/client.py", line 63, in create_client 
   cls = self._create_client_class(service_name, service_model) 
   File "/var/runtime/botocore/client.py", line 85, in _create_client_class 
   base_classes=bases) 
   File "/var/runtime/botocore/hooks.py", line 227, in emit 
   return self._emit(event_name, kwargs) 
   File "/var/runtime/botocore/hooks.py", line 210, in _emit 
   response = handler(**kwargs) 
   File "/var/runtime/boto3/utils.py", line 61, in _handler 
   module = import_module(module) 
   File "/var/runtime/boto3/utils.py", line 52, in import_module 
   __import__(name) 
   File "/var/runtime/boto3/s3/inject.py", line 13, in &lt;module&gt; 
   from boto3.s3.transfer import S3Transfer 
   File "/var/runtime/boto3/s3/transfer.py", line 135, in &lt;module&gt; 
   from concurrent import futures 
   File "/var/runtime/concurrent/futures/__init__.py", line 8, in &lt;module&gt; 
   from concurrent.futures._base import (FIRST_COMPLETED, 
   File "/var/runtime/concurrent/futures/_base.py", line 357 
   raise type(self._exception), self._exception, self._traceback 
   ^ 
  SyntaxError: invalid syntax 
  END RequestId: 2b65421a-664d-11e6-81db-974c7c09d283 
  REPORT RequestId: 2b65421a-664d-11e6-81db-974c7c09d283  Duration: 2673.45 ms    Billed Duration: 2700 ms Memory Size: 1024 MB   Max Memory Used: 61 MB  
  </code></pre>
  
  <p>I need to use boto3 downstream of run.py.  Any ideas on how to resolve this are much appreciated.  Thanks!</p>