Ashutosh Jha
Ashutosh Jha

Reputation: 16367

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/**

Upvotes: 4

Views: 9548

Answers (3)

MajinDageta
MajinDageta

Reputation: 282

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.

Upvotes: 5

Dharmendra Singh Negi
Dharmendra Singh Negi

Reputation: 393

change your serverless.yml file like this:

package:
  exclude:
    -./**
  include:
    -node-modules/**
    -lib/**

and in your function

function:
  functionname:
    handler: api/manageclient/addclient/handler.handler
    package:
      include:
       -api/manageclient/addclient/handler.js

Upvotes: 3

Deividi Silva
Deividi Silva

Reputation: 846

You can use the package and exclude configuration for more control over the packaging process.

Add this to your serverless.yml:

package:
  include:
    - node_modules/**
    - lib/** 
functions:
  yourfunctionname:
    handler: api/manageclient/addclient/handler.handler

For more information on including/excluding folders: https://serverless.com/framework/docs/providers/aws/guide/packaging/

Upvotes: 4

Related Questions