Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to deploy function using serverless so that it includes only required folder/files

    |--serverless.yml
    |--lib/
    |--node_modules/
    |--api/
        |--manageclient/
            |--addClient/
                |--handler.js

This is my folder structure , how to deploy function using serverless so that it includes only handler.js and node_modules/ and lib/.

Can you please specify the function command to be written on main serverless.yml?

My YML function statement

handler: api/manageclient/addClient/addclient.addclient
   package:
     exclude:
       - ./*
       - !api/manageclient/addClient/**
       - !api/node_modules/**
       - !api/lib/**
like image 822
Ashutosh Jha Avatar asked Oct 20 '25 08:10

Ashutosh Jha


1 Answers

This is my structure:

package:
  individually: true
  exclude:
    - ./**

and in my function:

functions:
  lambda:
    handler: dist/index.handler
    package:
      include:
        - 'dist/**/*'
        - '!dist/**/*.map'
        - '!node_modules/aws-sdk/**/*'

First you tell serverless you want to exlude everything and you say that each function will include their own files.

Inside each function I include everything inside a specific folder (as dist) and then to exclude specific files as files ending with .map or, for example, the aws-sdk library inside node modules.

like image 76
MajinDageta Avatar answered Oct 22 '25 22:10

MajinDageta