Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using Python 3 with AWS lambda

Can one use application built with Python3 in lambda, and not just python2.7. Possibly looking at options around - https://gun.io/blog/announcing-zappa-serverless-python-aws-lambda/

AWS lambda documentation mentions about python2.7.

Is there some example code which I could try for python3.0 with lambda

like image 564
jethar Avatar asked Mar 21 '16 23:03

jethar


People also ask

Does AWS support Python 3?

You can now use the Python 3.9 runtime to develop your AWS Lambda functions. To use this version, specify a runtime parameter value python3.

Can you run Python on AWS Lambda?

You can run Python code in AWS Lambda. Lambda provides runtimes for Python that run your code to process events. Your code runs in an environment that includes the SDK for Python (Boto3), with credentials from an AWS Identity and Access Management (IAM) role that you manage.

What version of Python does AWS Lambda use?

AWS Lambda supports Python 3.6, 3.7 and version 3.8. As always, you should test your functions for Python 3 language compatibility before applying changes to your production functions.


2 Answers

Lambda functions run in a container on a well-known AMI. While you must handle the initial event with Python2.7, you can call out to anything installed on the AMI. In particular, Python3 is already installed. It's a bit complicated, but you can establish a virtualenv to take advantage of the installed python3.

For a few of the details, see http://www.cloudtrek.com.au/blog/running-python-3-on-aws-lambda/.

Edit: that link went dead. Try https://www.linkedin.com/pulse/running-python-3-aws-lambda-lyndon-swan.

like image 50
Alex North Avatar answered Oct 08 '22 20:10

Alex North


Python 3.6 is now available in Ohio! (us-east-2)

I ran:

def lambda_handler(event, context):     # TODO implement     return sys.version 

And it kicked back:

"3.6.1 (default, Mar 27 2017, 23:56:45) \n[GCC 4.9.3]" 
like image 44
Ben Avatar answered Oct 08 '22 19:10

Ben