# Deploy - specify which serverless.yml file to deploy

**URL:** <https://forum.serverless.com/t/deploy-specify-which-serverless-yml-file-to-deploy/4917>\
**Category:** Serverless Framework\
**Created:** [June 29, 2018, 6:30pm UTC](https://forum.serverless.com/t/deploy-specify-which-serverless-yml-file-to-deploy/4917 "2018-06-29T18:30:00Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![diegol](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/diegol/32/2036_2.png) [@diegol](https://forum.serverless.com/u/diegol)\
**Post date:** [June 29, 2018, 6:30pm UTC](https://forum.serverless.com/t/deploy-specify-which-serverless-yml-file-to-deploy/4917/1 "2018-06-29T18:30:00Z")

</div>

Greetings,

**What I need:**  
Is there a way to specify which serverless.yml file I want to deploy?  
`sls deploy` uses serverless.yml to deploy but I have multiple .yml files (serverless-1.yml, serverless-2.yml so on) Why? I’ll explain it at the end.

**What I currently do:**

1. Change the name from serverless-1.yml to serverless.yml then `sls deploy`
2. Change the name from serverless.yml to serverless-1.yml then
3. Change the name from serverless-2.yml to serverless.yml then `sls deploy`

**What I need**  
To specify which .yml file I want to deploy so I don’t have to change the names to serverless.yml

`sls deploy --file serverless-1.yml`  
`sls deploy --file serverless-2.yml`

**Why do I have multiple YAML files under the same directory?**  
Well I’ve hit the CF 200 resources limit a long time ago, I’ve tried plugins such as split stacks, nested stacks and additional stacks none of them worked, so I’m using microservices now I have to divide my service into small services (30 or 35 functions per serverless.yml)

I realized that putting the serverless.yml file under a directory made that directory the microservice thus I could not invoke or use anything outside that directory (utils functions and node\_modules) I don’t want to put a node\_modules inside each microservice and I dont want to copy and paste my utils functions in each microservice (is obvious why), so I ended up having my microservices to be the same the only thing that changes is the yml file (inside the functions I declare) and the index.js file

---

<div class="post-metadata">

**Author:** ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)\
**Post date:** [June 30, 2018, 1:09am UTC](https://forum.serverless.com/t/deploy-specify-which-serverless-yml-file-to-deploy/4917/2 "2018-06-30T01:09:50Z")

</div>

> [@diegol](#):
>
> Is there a way to specify which serverless.yml file I want to deploy?

No.

This has been raised before at [Issues · serverless/serverless · GitHub](https://github.com/serverless/serverless/issues) but I don’t believe it’s ever been implemented.

The usual advice is to split your application into microservices. You can’t get around having a separate node\_modules for each microservice but that’s actually a good thing as it keeps your Lambda size down which helps at run time. Finally, if you have common utility functions I would recommend putting those into their own NPM package which you can use in your services.

---

<div class="post-metadata">

**Author:** ![diegol](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/diegol/32/2036_2.png) [@diegol](https://forum.serverless.com/u/diegol)\
**Post date:** [July 5, 2018, 2:39am UTC](https://forum.serverless.com/t/deploy-specify-which-serverless-yml-file-to-deploy/4917/3 "2018-07-05T02:39:41Z")

</div>

Thanks a lot buggy. It’s really hard to put my common functions in a npm package because it changes a lot and it connects to our databases.

---

<div class="post-metadata">

**Author:** ![bfieber](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/bfieber/32/653_2.png) [@bfieber](https://forum.serverless.com/u/bfieber)\
**Post date:** [July 6, 2018, 1:47pm UTC](https://forum.serverless.com/t/deploy-specify-which-serverless-yml-file-to-deploy/4917/4 "2018-07-06T13:47:32Z")

</div>

This may be a bit of a hack, but how about creating a deploy script for each one with that does something along the lines of:

------- deploy.sh ------

```auto
if [-z "$1"]; then
  echo "missing serverless id"
fi

id=$1
shift

if [-e "serverless.yml"]; then
  rm -f "serverless.yml"
fi

ln -s "serverless-$id.yml" serverless.yml
sls deploy $*

```

* * *

Then deploy by executing that script with the id and whichever parameters you wish to pass in like so:

> ./deploy.sh 1  
> ./deploy.sh 2 -s prod -v  
> ./deploy.sh 3 -s anotherstage -v

etc…

This all assumes that you’re using a bash shell such as bash on \*nix or git-bash on windows, etc…

Hope this helps.

---

<div class="post-metadata">

**Author:** ![robertdavidrowland](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/robertdavidrowland/32/1986_2.png) [@robertdavidrowland](https://forum.serverless.com/u/robertdavidrowland)\
**Post date:** [July 6, 2018, 2:36pm UTC](https://forum.serverless.com/t/deploy-specify-which-serverless-yml-file-to-deploy/4917/5 "2018-07-06T14:36:02Z")

</div>

Where I’ve needed to do something similar I’ve put serverless.tml files in a sub directory and ran my deploy scripts from there, but I bfieber’s idea of wrapping sls in scripts seems sound.

---

<div class="post-metadata">

**Author:** ![diegol](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/diegol/32/2036_2.png) [@diegol](https://forum.serverless.com/u/diegol)\
**Post date:** [July 6, 2018, 3:47pm UTC](https://forum.serverless.com/t/deploy-specify-which-serverless-yml-file-to-deploy/4917/6 "2018-07-06T15:47:40Z")

</div>

Hello @bfieber, nice solution just one observation, I don’t want to delete the serverless.yml (rm -f) I need to change its name then after deploy return its old name.

---

<div class="post-metadata">

**Author:** ![diegol](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/diegol/32/2036_2.png) [@diegol](https://forum.serverless.com/u/diegol)\
**Post date:** [July 6, 2018, 3:48pm UTC](https://forum.serverless.com/t/deploy-specify-which-serverless-yml-file-to-deploy/4917/7 "2018-07-06T15:48:35Z")

</div>

@robertdavidrowland I tried that and the zip file only had the sub directory contents thus no node\_modules and others files just the ones inside that subdirectory

---

<div class="post-metadata">

**Author:** ![bfieber](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/bfieber/32/653_2.png) [@bfieber](https://forum.serverless.com/u/bfieber)\
**Post date:** [July 6, 2018, 11:54pm UTC](https://forum.serverless.com/t/deploy-specify-which-serverless-yml-file-to-deploy/4917/8 "2018-07-06T23:54:40Z")

</div>

The rm -f is only removing the symbolic link(or on windows, the copy) left from the previous run if it exists.

Instead of trying to do the rename dance and hope nothing gets lost, just using a symlink keeps the originals around and makes the one you’re currently needing look like serverless.yml

Not sure why you’re not getting your node\_modules. I tested it in my environment as and it worked perfectly.  
Are you using a bash script friendly shell?  
If not, you can re-write it as a windows script file.

---

<div class="post-metadata">

**Author:** ![diegol](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/diegol/32/2036_2.png) [@diegol](https://forum.serverless.com/u/diegol)\
**Post date:** [July 7, 2018, 3:31pm UTC](https://forum.serverless.com/t/deploy-specify-which-serverless-yml-file-to-deploy/4917/9 "2018-07-07T15:31:43Z")

</div>

@bfieber oh Nice one I’ll try it, I have windows OS but I use git bash so your sh will work, I’ll try again the subdirectories to see if it packages only the files where the .yml is

---

<div class="post-metadata">

**Author:** ![diegol](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/diegol/32/2036_2.png) [@diegol](https://forum.serverless.com/u/diegol)\
**Post date:** [July 7, 2018, 9:28pm UTC](https://forum.serverless.com/t/deploy-specify-which-serverless-yml-file-to-deploy/4917/10 "2018-07-07T21:28:52Z")

</div>

It removed my serverless.yml file it didn’t even created the SL

---

<div class="post-metadata">

**Author:** ![ktwbc](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/ktwbc/32/764_2.png) [@ktwbc](https://forum.serverless.com/u/ktwbc)\
**Post date:** [August 7, 2019, 10:09pm UTC](https://forum.serverless.com/t/deploy-specify-which-serverless-yml-file-to-deploy/4917/11 "2019-08-07T22:09:27Z")

</div>

This is an old thread but ran across it and wanted to post for anyone finding it still. Simplest was to combine the copying mentioned above in the package.json. In the root of my folder I have two serverless files, serverless-public.yml and serverless-admin.yml and then the two scripts just pull one and copy it:

```
   "start-dev-public": "rm -f serverless.yml && cp serverless-public.yml serverless.yml && sls offline start --stage=dev --port=4000",
   "start-dev-admin": "rm -f serverless.yml && cp serverless-admin.yml serverless.yml && sls offline start --stage=dev --port=4999",
```

---

<div class="post-metadata">

**Author:** ![peter\_v](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/peter_v/32/3968_2.png) [@peter\_v](https://forum.serverless.com/u/peter_v)\
**Post date:** [February 10, 2020, 1:42pm UTC](https://forum.serverless.com/t/deploy-specify-which-serverless-yml-file-to-deploy/4917/12 "2020-02-10T13:42:47Z")

</div>

This is now possible with the `--config` option.

Please Note that the `-c` option seems broken at this time.

---

<div class="post-metadata">

**Author:** ![AntonioCS](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/antoniocs/32/4039_2.png) [@AntonioCS](https://forum.serverless.com/u/AntonioCS)\
**Post date:** [March 5, 2020, 4:19pm UTC](https://forum.serverless.com/t/deploy-specify-which-serverless-yml-file-to-deploy/4917/13 "2020-03-05T16:19:15Z")

</div>

Hey,

I can’t find an example of this anywhere. Can you please provide some example on how to select a different yml?

Thanks

EDIT: Right… it’s as easy as you would think… just serverless -c   
Not sure why I thought you would have to pass more stuff  
Thanks

---

<div class="post-metadata">

**Author:** ![tomeraz](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/tomeraz/32/4440_2.png) [@tomeraz](https://forum.serverless.com/u/tomeraz)\
**Post date:** [July 28, 2020, 5:09pm UTC](https://forum.serverless.com/t/deploy-specify-which-serverless-yml-file-to-deploy/4917/14 "2020-07-28T17:09:35Z")

</div>

When I specify serverless --config ./path/to/serverless.yml it works fine, but I have a plugin there and it errors that the plugin is not found. Can I set a node\_modules as well?

---

<div class="post-metadata">

**Author:** ![nbcch](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/nbcch/32/7422_2.png) [@nbcch](https://forum.serverless.com/u/nbcch)\
**Post date:** [April 14, 2023, 2:19pm UTC](https://forum.serverless.com/t/deploy-specify-which-serverless-yml-file-to-deploy/4917/15 "2023-04-14T14:19:22Z")

</div>

do you have the docs?
