agutoli / serverless-layers

Serverless.js plugin implementing AWS Lambda Layers, reducing lambda size, warm-up, and deployment time.
MIT License
229 stars 54 forks source link

package.exclude from the serverless.yml is being ignored #118

Closed stanyq4 closed 10 months ago

stanyq4 commented 1 year ago

In the serverless.yml, I am specifying the following node modules to be excluded as part of the layer:

package:
  excludeDevDependencies: true
  exclude:
    - node_modules/@aws-sdk/**
    - node_modules/@azure/**
    - node_modules/@baemingo/**
    - node_modules/sqreen/**
    - node_modules/sqreen-info/**

AWS SDK is around 50MB and is included by default in all lambdas, so it makes no sense to package it as part of the layer.

However, when the layer is being created it still includes the @aws-sdk folder from node_modules

Created layer package /Users/stanyeshchenko/Dev/projects/api-demo/.serverless/api-demo-nodejs-default.zip (88.9 MB)

Attaching a screenshot with layer that I downloaded from S3, you can see that aws-sdk is not excluded

Screen Shot 2022-10-01 at 11 19 39 AM
agutoli commented 1 year ago

PR to review: https://github.com/agutoli/serverless-layers/pull/131

Usage:

package:
  patterns:
    - '!node_modules/express/**'
    - 'node_modules/**'

Reference: https://www.serverless.com/framework/docs/providers/aws/guide/packaging

(It wasn't release yet, but probably will be on next version).

lmzbonack commented 1 year ago

If you could merge this bad boy that would be pretty cool. Thanks

fyelci commented 1 year ago

@agutoli Thanks for the fix. Can you please merge it?

m0uneer commented 1 year ago

As a workaround, install clean-modules npm module and use customInstallationCommand option to call npm ci --omit=dev --ignore-scripts && clean-modules -y and set up a .cleanmodules file with the patterns you want to exclude.

Bonus: If you want to include, you can use this undocumented option copyBeforeInstall

  serverless-layers:
    copyBeforeInstall:
      - package-lock.json
      - path/to/custom/files # This file will be part of the layers
agutoli commented 10 months ago

please try: serverless-layers@2.7.0

lmzbonack commented 10 months ago

Thanks @agutoli :)