简体   繁体   English

将 Python 3 与 AWS lambda 结合使用

[英]using Python 3 with AWS lambda

Can one use application built with Python3 in lambda, and not just python2.7.可以在 lambda 中使用用 Python3 构建的应用程序,而不仅仅是 python2.7。 Possibly looking at options around - https://gun.io/blog/announcing-zappa-serverless-python-aws-lambda/可能正在查看周围的选项 - https://gun.io/blog/annoucing-zappa-serverless-python-aws-lambda/

AWS lambda documentation mentions about python2.7. AWS lambda 文档提到了 python2.7。

Is there some example code which I could try for python3.0 with lambda是否有一些示例代码,我可以尝试使用 lambda 为 python3.0

Lambda functions run in a container on a well-known AMI . Lambda 函数在众所周知的 AMI上的容器中运行。 While you must handle the initial event with Python2.7, you can call out to anything installed on the AMI.虽然您必须使用 Python2.7 处理初始事件,但您可以调用 AMI 上安装的任何内容。 In particular, Python3 is already installed.特别是已经安装了 Python3。 It's a bit complicated, but you can establish a virtualenv to take advantage of the installed python3.这有点复杂,但是您可以建立一个 virtualenv 来利用已安装的 python3。

For a few of the details, see http://www.cloudtrek.com.au/blog/running-python-3-on-aws-lambda/ .有关一些详细信息,请参阅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 .试试https://www.linkedin.com/pulse/running-python-3-aws-lambda-lyndon-swan

Python 3.6 is now available in Ohio! Python 3.6 现已在俄亥俄州推出! (us-east-2) (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]"

Lambda 现在完全支持 Python 3.6。

You can use Python 3 with aws lambda.您可以将 Python 3 与 aws lambda 结合使用。 when you are creating an Aws lambda function there is an option where you can use a python 3 as a version and execute your code.当您创建 Aws lambda 函数时,您可以选择使用python 3作为版本并执行代码。

将运行时语言更改为 python 版本 3。https ://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM