简体   繁体   English

使用无服务器框架将库/依赖项注入 AWS Lambda

[英]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.jsonpackage-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.

相关问题 无服务器框架-AWS Lambda依赖项限制超出 - Serverless Framework - AWS Lambda dependency limit exceed 如何在 S3 上存储大型 Python 依赖项(适用于无服务器的 AWS Lambda) - How to Store Large Python Dependencies on S3 (for AWS Lambda with Serverless) 无服务器框架 / Lambda 的 Python - 打包本地共享库 - Serverless Framework / Python for Lambda - packaging up local shared libraries 使用无服务器框架将 Python package 部署到 AWS lambda 时出错 - Error deploying Python package to AWS lambda using Serverless framework 使用无服务器框架为 AWS Lambda 构建和使用本地包 - Build and use local package for AWS Lambda using serverless framework 通过 GitHub 操作和无服务器框架部署 AWS Lambda 时找不到好的绑定路径格式 - Unable to find good bind path format when deploying AWS Lambda via GitHub action and serverless framework 如何在无服务器框架中将外部 python 模块导入您的 AWS Lambda 函数? - How to import external python modules to your AWS Lambda functions, in serverless framework? AWS Lambda 和 Python 中的 Open CV 的无服务器问题 - Serverless issue with AWS Lambda and Open CV in Python 无服务器框架 Python lambda 直接返回 JSON - Serverless Framework Python lambda return JSON directly 在AWS Lambda中组织外部依赖项 - Organizing external dependencies in AWS lambda
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM