python - 如何在 Windows 操作系统上使用 zip 文件编写 AWS Python3 Lambda 函数

标签 python amazon-web-services aws-lambda twilio python-3.6

我已经仔细查找了有关在 Windows 操作系统上使用 Lambda 管理控制台从 zip 文件创建 python3 lambda 函数的教程或帮助。不幸的是,我很不幸。这就是我现在所处的位置...

按照 AWS 网站上的说明进行操作:https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html

  • 我在桌面上创建了一个名为“APP”的文件夹。在该文件夹中,我在“App”的根级别保存了一个包含名为“twilio_test.py”的 python 代码的文件。

我的Python代码:

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")
  • 由于我使用的是 twilio 库,因此我根据上述链接中的说明将其安装在“APP”文件夹的根目录中。说明特别指出,“使用 pip 安装任何库。同样,您将这些库安装在目录的根级别。”:

pip install twilio -t\path\to\directory

  • 然后,我根据引用的指令压缩“APP”的内容,“压缩 project-dir 目录的内容,这是您的部署包。压缩目录内容,而不是目录。”这将创建一个名为“twilio_test”的 zip 文件。

  • 然后,我转到 AWS lambda 管理控制台,上传 zip 文件“twilio_test”。

这就是我感到困惑的地方。处理程序应该是什么?

到目前为止,我是否正确完成了所有操作?如果没有,安装 twilio、压缩文件然后在 AWS lambda 中使用它的最佳方法是什么?

虽然说 AWS lambda 本质上很难使用是不恰当的,但我可以说我本质上很困惑。

最佳答案

您应该将处理程序设置为python_file_name.function_name。因此,在您的情况下,它应该是 twilio_test.lambda_handler

来自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) ...

关于python - 如何在 Windows 操作系统上使用 zip 文件编写 AWS Python3 Lambda 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48218263/

相关文章:

python - 远程服务提供用户信息时如何使用 Flask-Login?

amazon-web-services - 在 AWS CloudFormation 中创建负载均衡器失败

amazon-ec2 - 在 Amazon Elastic Block Storage(EBS) 中创建目录结构并从 Java Servlet 保存文件?

amazon-web-services - 使用 CloudFormation 在 EC2 上设置 IIS

aws-lambda - 如何在 lambda 函数中加载大文件模型

amazon-web-services - 如何根据 Cognito 用户池(或 DynamoDB)中的用户属性实现授权?

amazon-web-services - 如何保护联系表免受 AWS Lambda 和 API 网关处理的垃圾邮件

python - 在非常具体的约束下生成随机数

python - 将 csv 转换为字典

python - 无法在 python 中从 sklearn 重现 GridSearch