AWS Lambda和python numpy模块 [英] AWS Lambda and python numpy module

查看:67
本文介绍了AWS Lambda和python numpy模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在aws lambda中导入python部署程序包. python代码使用numpy.我按照虚拟环境的部署程序包说明进行操作,但仍然给出了缺少必需的依赖项['numpy'].我按照堆栈溢出中给出的说明进行操作(跳过了第4步)对于共享库,找不到任何共享库),但没有运气.有什么建议可以使其正常工作吗?

I am trying to import a python deployment package in aws lambda. The python code uses numpy. I followed the deployment package instructions for virtual env but it still gave Missing required dependencies ['numpy']. I followed the instruction given on stack overflow (skipped step 4 for shared libraries, could not find any shared libraries) but no luck. Any suggestions to make it work?

推荐答案

最简单的方法是使用AWS Cloud9,无需启动EC2实例并准备部署程序包.

The easiest way is to use AWS Cloud9, there is no need to start EC2 instances and prepare deployment packages.

  • 转到AWS控制台并选择Cloud9服务.
  • 创建环境
  • 输入名称
  • 环境设置(考虑使用t2.small实例类型,默认情况下,我有时在重启环境时会遇到问题)
  • 查看
  • 点击创建环境
  • 创建Lambda函数(屏幕底部)
  • 输入功能名称和应用程序名称
  • 选择运行时(Python 3.6)和蓝图(empty-python)
  • 功能触发器(无)
  • 创建无服务器应用程序(保留默认设置)
  • 完成
  • 等待几秒钟以打开IDE
  • 在屏幕底部有一个命令提示符
  • 转到Application文件夹,对我来说这是

  • at the bottom of the screen there is a command prompt
  • go to the Application folder, for me this is

cd App

  • 安装软件包(我们必须在虚拟环境中使用pip,因为默认pip指向/usr/bin/pip,而这是python 2.7)

  • install the package (we have to use pip from the virtual environment, because the default pip points to /usr/bin/pip and this is python 2.7)

    venv/bin/pip install numpy -t .
    

    • 您可以通过编辑lambda_function.py文件来测试安装:

    • you can test the installation by editing the lambda_function.py file:

    import numpy as np
    def lambda_handler(event, context):
        return np.sin(1.0)
    

  • 保存更改,然后单击屏幕顶部的绿色运行"按钮

  • save the changes and click the green Run button on the top of the screen

    在执行Lambda之后,我得到:

    after the Lambda executes I get:

    Response
    0.8414709848078965
    

    • 在屏幕右侧选择您的Lambda函数
    • 点击向上的箭头进行部署
    • 转到AWS Lambda服务选项卡
    • Lambda函数应该可见,名称格式为

    • on the right hand side of the screen select your Lambda function
    • click the upwards pointing arrow to deploy
    • go to the AWS Lambda service tab
    • the Lambda function should be visible, the name has the format

    cloud9-ApplicationName-FunctionName-RandomString
    

    这篇关于AWS Lambda和python numpy模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆