# How to Ignore directories and files for a deployment

**URL:** <https://forum.serverless.com/t/how-to-ignore-directories-and-files-for-a-deployment/2624>\
**Category:** Serverless Framework\
**Created:** [September 1, 2017, 11:02pm UTC](https://forum.serverless.com/t/how-to-ignore-directories-and-files-for-a-deployment/2624 "2017-09-01T23:02:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JLee21](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/jlee21/32/950_2.png) [@JLee21](https://forum.serverless.com/u/JLee21)\
**Post date:** [September 1, 2017, 11:02pm UTC](https://forum.serverless.com/t/how-to-ignore-directories-and-files-for-a-deployment/2624/1 "2017-09-01T23:02:55Z")

</div>

Hi!

**Problem** : my zipped deployment folder that contains my python code is too big!  
I looked inside and there’s stuff in there that should be ignored according to my .gitignore

Here is my .gitignore

![image](https://canada1.discourse-cdn.com/flex036/uploads/serverless/original/1X/d7f4f2d3857c9f1ea3f83e70cd813b643b5fe84d.png)

Here is the contents of my .gitignore

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/serverless/original/1X/73a5cacad7700def3a5f9debbf949ba55731a288.png)

Here is the contents of the (too-big) zipped folder that is deployed to S3  
(I DL it from S3 and unzipped the contents)

![image](https://canada1.discourse-cdn.com/flex036/uploads/serverless/original/1X/d726d6b57195193d88b9822b746f1560ba2b5a18.png)

I should note that my service project is nested one level below another service project, like so…  
-root  
—main.project.with.own.deployment  
------my.project.with.big.zip  
---------.gitignore  
---------handler.py  
--------etc…

This is the command I’m using to deploy

```
sudo sls deploy -f numpy

```

Thanks!

---

<div class="post-metadata">

**Author:** ![hackman](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/hackman/32/1727_2.png) [@hackman](https://forum.serverless.com/u/hackman)\
**Post date:** [September 2, 2017, 11:47pm UTC](https://forum.serverless.com/t/how-to-ignore-directories-and-files-for-a-deployment/2624/2 "2017-09-02T23:47:22Z")

</div>

Serverless does not pay attention to .gitignore. You have a few options for you to take that I use myself.

1. You can add options to the serverless.yml to indicate what to exclude and what to include. You can read about that at [https://serverless.com/framework/docs/providers/aws/guide/packaging/](https://serverless.com/framework/docs/providers/aws/guide/packaging/)

2. What I do most recently is use gulp to build a deployment folder containing all my files/folders. Then within that folder is what I actually deploy. This allows me to have more processes in place for CI/CD.

---

<div class="post-metadata">

**Author:** ![JLee21](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/jlee21/32/950_2.png) [@JLee21](https://forum.serverless.com/u/JLee21)\
**Post date:** [September 3, 2017, 1:17am UTC](https://forum.serverless.com/t/how-to-ignore-directories-and-files-for-a-deployment/2624/3 "2017-09-03T01:17:02Z")

</div>

Perfect. Thanks so much!

---

<div class="post-metadata">

**Author:** ![shentonfreude](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/shentonfreude/32/346_2.png) [@shentonfreude](https://forum.serverless.com/u/shentonfreude)\
**Post date:** [September 6, 2017, 7:11pm UTC](https://forum.serverless.com/t/how-to-ignore-directories-and-files-for-a-deployment/2624/4 "2017-09-06T19:11:54Z")

</div>

We a single serverless.yml that contains a bunch of resources and 4 python lambdas. Each lambda needed a different set of python libraries and pre-compiled binaries. I found the best way to hald this was to “package individually” and exclude _everything_:

```auto
package:
  individually: true
  exclude:
    - ".*/**"

```

Then in each lambda, include only the binaries/libs I needed. e.g.,

```auto
functions:
  DocPdfSplit:
    handler: doc_pdf_split.s3created
    package:
      include:
        - doc_pdf_split.py
        - lib.py
        - ghostscript-9.20/**
    events:
      - s3:
          bucket: ${self:custom.s3_name}
          event: s3:ObjectCreated:*

```

and

```auto
  PageTxtCombine:
    handler: page_txt_combine.s3created
    package:
      include:
        - page_txt_combine.py
        - lib.py
        - elasticsearch/**
        - urllib3/**
    events:
      - s3:
          bucket: ${self:custom.s3_name}
          event: s3:ObjectCreated:*

```

---

<div class="post-metadata">

**Author:** ![ChrisGrigg](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/chrisgrigg/32/1361_2.png) [@ChrisGrigg](https://forum.serverless.com/u/ChrisGrigg)\
**Post date:** [March 9, 2020, 9:38pm UTC](https://forum.serverless.com/t/how-to-ignore-directories-and-files-for-a-deployment/2624/5 "2020-03-09T21:38:25Z")

</div>

What @shentenfruede said above works well putting “exclude” under “package”. On Mac I needed to use:

```
package:
  individually: true
  exclude:
    - "*/**"
```

---

<div class="post-metadata">

**Author:** ![vijayakumar-psg587](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/vijayakumar-psg587/32/5701_2.png) [@vijayakumar-psg587](https://forum.serverless.com/u/vijayakumar-psg587)\
**Post date:** [February 3, 2023, 6:40am UTC](https://forum.serverless.com/t/how-to-ignore-directories-and-files-for-a-deployment/2624/6 "2023-02-03T06:40:29Z")

</div>

With the new release, include and exclude are depreciated and will be removed completely in future releases. Please adhere to

> patterns  
> Here is an example:

```auto
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!

service: python-sls-test

frameworkVersion: '3'
configValidationMode: error

custom:
  SERVICE_NAME: ${env:SERV_NAME, 'python-default'}
  REGION: ${env:AWS_REGION, 'us-east-1'}

provider:
  name: aws
  runtime: python3.9
  stage: ${opt:stage, 'dev'}
  region: us-east-1
  deploymentMethod: direct
  memorySize: 512
  deploymentPrefix: serverless
  deploymentBucket:
    name: sls-vj-deploy
    maxPreviousDeploymentArtifacts: 3

# you can add packaging information here
package:
 
 patterns:
   - '!exclude-me.py'
   - '!venv/**'
   - '!README.md'
   - '!build/**'
  # Package each function individually 
 individually: true

functions:
  testFunction:
    handler: lambdas/handler.test
    package: 
      patterns:
        - lambdas/**

```
