[英]Injecting libraries/dependencies into AWS Lambda with Serverless Framework
really quick question;非常快的问题; do I need to install from the command prompt
sls plugin install -n serverless-python-requirements
into each serverless framework project that I make to load python dependencies into the stack/lambda function I am going to deploy?我是否需要从命令提示符
sls plugin install -n serverless-python-requirements
到我制作的每个无服务器框架项目中,以便将 python 依赖项加载到我要部署的堆栈/lambda 函数中?
I had been playing with Serverless Framework in trying to use it for a project involving AWS Lambda and python for csv transformations.我一直在使用无服务器框架,试图将它用于一个涉及 AWS Lambda 和 python 的项目以进行 csv 转换。 As such I'd like to use pandas and numpy within the Lambda function.
因此,我想在 Lambda 函数中使用 pandas 和 numpy。
I have Docker installed and in the yaml file have我已经安装了 Docker 并且在 yaml 文件中有
custom:
pythonRequirements:
dockerizePip: true
plugins:
- serverless-python-requirements
But was wondering if I need to repeatedly install that sls plugin install -n serverless-python-requirements
each time I create a new project.但是想知道我是否需要在每次创建新项目时重复安装该
sls plugin install -n serverless-python-requirements
。 I noticed that if I do that it downloads two json documents package-lock.json and package.json into the project folder.我注意到,如果我这样做,它会将两个 json 文档 package-lock.json 和 package.json 下载到项目文件夹中。 But I had noticed though that other tutorials did not have those json files despite using dependencies, so I wasn't quite sure if this is a repeated step I do per project.
但是我注意到尽管使用依赖项,但其他教程没有那些 json 文件,所以我不太确定这是否是我每个项目重复执行的步骤。
Great question!好问题!
The Serverless Framework is a project written in NodeJS. Serverless Framework 是一个用 NodeJS 编写的项目。
Specifically sls plugin install
basically just runs npm install
under the hood .具体
sls plugin install
基本上只运行npm install
下罩。 This means that sls plugin install
just fetches the plugin from NPM and installs it (via adding it to the project package.json
and package-lock.json
)这意味着
sls plugin install
只是从 NPM 获取插件并安装它(通过将它添加到项目package.json
和package-lock.json
)
I'd guess you can likely run npm i -g serverless-python-requirements
to install the library globally for your system, and then I suspect you could just declare the plugin in the plugins
block of each project's serverless.yml
file, and be done.我猜你可能会运行
npm i -g serverless-python-requirements
来为你的系统全局安装库,然后我怀疑你可以在每个项目的serverless.yml
文件的plugins
块中声明插件,然后完毕。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.