1

I have looked all over for a tutorial or help on creating a python3 lambda function from a zip file using the Lambda Management Console on Windows OS. I have, unfortunately, been unlucky. Here is where I am at...

Following the instructions on the AWS website here: https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html

  • I create a folder on my desktop called 'APP'. In that folder I save a file with my python code called 'twilio_test.py' at the root level of 'App'.

My Python code:

import twilio

def lambda_handler(event, context):
    account_sid = '##########################'
    auth_token = '###########################'

    client = Client(account_sid, auth_token)

    message = client.messages.create(
            to = '###########',
            from_ = '###########',
            body = "Test")
    return("success")
  • Since I am using the twilio library I pip install it in the root of my 'APP' folder based on the instructions found in the above link. The instructions say specifically, "Install any libraries using pip. Again, you install these libraries at the root level of the directory.":

pip install twilio -t \path\to\directory

  • I then zip the contents of 'APP' based on the quoted instruction, "Zip the content of the project-dir directory, which is your deployment package. Zip the directory content, not the directory." This creates a zip file called 'twilio_test'.

  • I then go to the AWS lambda management console, upload the zip file 'twilio_test'.

Here is where I am getting confused. What should be the handler?

Have I correctly done everything so far up until this point? If not, what is the best way to go about installing twilio, zipping a file and then using it in AWS lambda?

Although it is inappropriate to say that AWS lambdas are inherently difficult to use, I can say that I am inherently confused.

user111417
  • 143
  • 1
  • 9
  • check out [this answer](https://stackoverflow.com/a/48208108/3196845), that might solve your problem. also `handler` is `python_file.entry_function` so it would be `twilio_test.lambda_handler` – sid8491 Jan 12 '18 at 05:19
  • 1
    Thank you @sid8491. That answer gave much more clarity. I had been following the steps right but was using anaconda to do the pip install of twilio. I instead used powershell and that worked. – user111417 Jan 12 '18 at 05:47
  • Please see my answer below. It wasn't an issue of anaconda vs powershell. I needed to specify the full file path. – user111417 Jan 12 '18 at 06:17

2 Answers2

2

You should set the handler to python_file_name.function_name. So in your case it should be twilio_test.lambda_handler.

From the documentation:

... You specify the function name in the Python code to be used as the handler when you create a Lambda function. For instructions to create a Lambda function using the console, see Create a Simple Lambda Function. In this example, the handler is hello_python.my_handler (file-name.function-name) ...

kichik
  • 33,220
  • 7
  • 94
  • 114
2

Originally I thought doing the pip install with anaconda was the issue, so I used powershell. That worked, but only because I specified the full file path, as @sid8491 pointed out here.

I originally used:

<C:\ProgramData\Anaconda3> C:\Users\userName> pip install twilio -t \Desktop\APP

which did not work

But using:

<C:\ProgramData\Anaconda3> C:\Users\userName> pip install twilio -t  C:\Users\userName\Desktop\APP

Did Work

And that will work in powershell or anaconda

user111417
  • 143
  • 1
  • 9