简体   繁体   中英

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?

I had been playing with Serverless Framework in trying to use it for a project involving AWS Lambda and python for csv transformations. As such I'd like to use pandas and numpy within the Lambda function.

I have Docker installed and in the yaml file have

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. I noticed that if I do that it downloads two json documents package-lock.json and package.json into the project folder. 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.

Great question!

The Serverless Framework is a project written in NodeJS.

Specifically sls plugin install basically just runs npm install under the hood . 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 )

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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