'How to deploy multiple functions using serverless cli?
From the doc, I can deploy a function like this
serverless deploy function -f functionName
https://www.serverless.com/framework/docs/providers/aws/cli-reference/deploy-function/
Can I deploy multiple functions with a command like this?
serverless deploy function -f functionName1, functionName2
If can't, what should I do deploy multiple functions at once?
Thanks
Solution 1:[1]
The serverless-cli does not support deploying multiple functions in one go. I'm attached a bash function that you can add to your bashrc so it's always loaded automatically for you (instead of copy-ing and past-ing it when opening a new terminal)
serverless-deploy-function() {
# Validate at least one parameter is passed
[ "$#" -ne 1 ] && echo "USAGE $0 <PARAMETER>" && return 2
# create a list of the first parameter (split by ,)
declare -a FUNCTIONS_TO_DEPLOY=($(echo $1 | tr "," " "))
# remove the first parameter from $@
shift;
# loop on the list of functions to deploy
for x in $FUNCTIONS_TO_DEPLOY
do
echo Running \"serverless deploy function -f $x $@\"
# Pass one function at a time and keep the rest of the arguments the same
serverless deploy function -f $x $@
done
}
To use it, you'll need to do something like this:
$ serverless-deploy-function function1,function2
Keep in mind, this should also support extra parameters given that you add them after the function(s) you want to deploy:
$ serverless-deploy-function function1,function2 --stage dev --region us-east-1
or for one function, as follows:
$ serverless-deploy-function function1 --stage dev --region us-east-1
Solution 2:[2]
I couldn't quite figure out how to do this in Windows, but running the following batch script will generate the multiple individual lines you'd normally use. You can then copy and paste them back into the commandline to run them sequentially.
:: used as >> deploy-functions STAGE fn1 fn2 fn...
@echo off
SET stage=%1
shift
:loop
echo serverless deploy --stage %stage% -f %1
shift
if not "%~1"=="" goto loop
I tried piping the output to a single batch file, but running that file stops after the first line.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mostafazh |
Solution 2 | drzaus |