JLuu
JLuu

Reputation: 373

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.

Upvotes: 1

Views: 705

Answers (1)

Aaron Stuyvenberg
Aaron Stuyvenberg

Reputation: 3777

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.

Upvotes: 2

Related Questions