Feature branching and AWS APIGateway name

Hi all, I am trying to use a feature branching strategy and setting my branch name to be the name of the serverless stage e.g. sls deploy --stage=my-new-feature. However I get this error from the AWS APIGateway - “Stage name only allows a-zA-Z0-9_.” Is there a known way of dealing with this?

Use sls deploy --stage=my_new_feature

I believe this is a limitation of cloudformation naming conventions

Thanks David. My team tends to used ‘-’ in branch names in git. Is there a serverless way to convert the dashes to underscores or should I use a script to preporcess the stage name?

Here’s one I just created that accomplishes what you’re looking for. It grabs the current branch name and converts all non-ASCII characters into underscores:

branchname=$( git branch | grep \* | cut -d ' ' -f2- ) && sanitized_branchname=${branchname//[^a-zA-Z0-9]/_} && echo $sanitized_branchname

$sanitized_branchname is what you want.

I’d just throw this into an npm script and boom!

An example of a weird branch name being converted: