cyberguy
cyberguy

Reputation: 253

How to include package.json using serverless deploy?

I am using webpack and serverless to deploy to aws lambda. So far I have been able to configure it to bundle all dependencies into one ts file, but aws complains there is no package.json. So, I found a way to upload the node modules folder as well, which also brought in the package.json but since I am on windows the aws instances don't like the libraries.

How do I include package.json when I run the serverless package or deploy commands so that aws lambda can run the install?

include:
      - package.json

Doesn't work.

Upvotes: 1

Views: 2665

Answers (1)

Gabe Hollombe
Gabe Hollombe

Reputation: 8067

If you're using the Serverless Webpack plugin, you should be able to get whatever native modules you need installed by using the packagerOptions config for the plugin and specifying the linux platform for x64 architecture along with the list of npm modules to package.

See the Custom scripts section of the plugin's documentation for more info.

For example, if your Lambda function depends on the sharp npm package, you'd add something like the following to your serverless.yml file:

custom:
  webpack:
    includeModules: true
    packagerOptions:
      scripts:
        - npm_config_platform=linux npm_config_arch=x64 yarn add sharp

Upvotes: 1

Related Questions