title: how to upload python code with libraries to aws lambda from windows local machine using aws console
body: <p>I need to use AWS Lambda triggered through API gateway. I have python script which loads a machine learning model from S3bucket and gets input from api call and predicts the result. I can successfully trigger the lambda function written inline in python. But I want to use machine learning packages to predict in lambda function. So I came to know that I need to upload the code with the packages installed in virtual environment and I did.But the lambda when triggered gives the error 'Unable to import model lambda_function'. I have lambda_function.py with method 'handler'. Please let me know if Iam doing it right(creating virtual env and installing packages and uploading it) and why is this error. Also, let me know the solutions for Windows and AWS console. I have seen many answers with Linux commands and using aws cli.</p>
  
  <p><a href="https://i.stack.imgur.com/0yreH.png" rel="nofollow noreferrer">zip folder</a></p>
  
  <p><a href="https://i.stack.imgur.com/2JtlM.png" rel="nofollow noreferrer">lambda_function</a></p>
  
  <p><a href="https://i.stack.imgur.com/z4yWt.png" rel="nofollow noreferrer">lamnda function settings</a></p>
  
  <p><a href="https://i.stack.imgur.com/r2ckJ.png" rel="nofollow noreferrer">lambda function settings</a></p>
  
  <p>Update:</p>
  
  <p>This is driving me crazy!. I have tried all the methods found in the answers and none works for me. And it gives the same error : 'Unable to import module : lambda_function' So Iam not able to understand where the error is. Please help me if you have any suggestion. Before you say function names: I have correct names: lambda_function.lambda_handler. I zipped the contents and not directory. Please see my lambda code and lambda settings below
  <a href="https://i.stack.imgur.com/MJdAP.png" rel="nofollow noreferrer">lambda json file</a> 
  lambda function code:
      import boto3
      import os
      import uuid
      import sklearn
      import pickle</p>
  
  <pre><code>def lambda_handler(event, context):
  s3_client = boto3.client('s3')
  s_desc=event['params']['querystring']['token']
  X_test1=[]
  X_test1.append(s_desc)
  #load model
  bucket = 'harshini-snow-bucket'
  key = 'model.pkl'
  download_path = '/tmp/{}{}'.format(uuid.uuid4(), key)
  s3_client.download_file(bucket, key, download_path)
  
  f = open(download_path, 'rb')
  model = pickle.load(f)
  f.close()
  #class_predicted = model.predict(X_test1)
  
  return X_test1
  </code></pre>
  
  <p>Please tell me if there are any other ways.. I will try anything for this to work.</p>
  
  <p>Update 2:</p>
  
  <p><a href="https://i.stack.imgur.com/CpmjX.png" rel="nofollow noreferrer">error</a></p>
  
  <p><a href="https://i.stack.imgur.com/goxNc.png" rel="nofollow noreferrer">code</a></p>