Using The Serverless Framework To Easily Deploy To Multiple Environments

Corey Walker
Oct 2, 2019 · 3 min read

Do you currently use a serverless configuration for any of applications or are interested in migrating a current application to a serverless architecture? Have you wondered how you can easily configure your CI/CD pipeline to easily deploy to multiple environments such as development, staging, and all production environments? With the Serverless Framework you can do just that. Continue reading to find out how.


Currently, I use the Serverless Framework to deploy to multiple environments and regions on the AWS cloud. I deploy to our development, staging, and production environments. Our development and staging environments are deployed into 2 different regions and our production environment is deployed to 4 different regions for both failover and latency improvements. So I have a serverless.yml file with many properties found in the docs for serverless.yml found here.

In order to automatically deploy to multiple environments based on the git branch code is pushed to, I have setup my configuration as follows:

  • All properties that remain the same for all environments and/or regions go into the serverless.yml base file
  • For all properties that are different between each environment such as development, staging, and production, I have another config file with the following naming convention under my config/ directory (the same naming I have is not required, but just what i use):
  • config/config.dev.yml, config/config.stg.yml, config/config.prod.yml, etc

Following this guide I add all the needed custom properties to those environment specific config files, and then in the main serverless.yml file, I create the same property, but then reference the property from the environment/stage specified on the serverless deploy -s {stage}CLI command. I use a combination of both the stage CLI parameter and setting a ENV variable in a bash script before calling serverless deploy . Then i can also use ${env:ENV} to reference that value inside serverless.yml .

Here’s an example of an environment specific YAML configuration file i have for environment specific variables:

And inside serverless.yml, I reference those values by doing the following:

Also, using a lot of shell environment based variables allows you to make your serverless config even more decoupled away from specific projects/microservices since you then can just create a .env file specific to each project, create a bash script to run your serverless deploycommands, and before running serverless deploy, run source .env and many values can be populated easily by just supplying your .env file


Lastly, here’s an example of the bash script we use to run our serverless deploy commands that will supply many of our values in serverless.yml with values from a .env file instead of manually finding and replacing all the values between all our different microservices:

and the .env file we use to supply the variable values:

Let me know what you think and if you also see any improvement I myself could make to this process!


If you found this article to be of help, please follow this publication if you are interested in seeing more like it!

Technology Today

Software Development, Cyber Security, DevOps, SEO, and Analytics

Corey Walker

Written by

Owner of SDVOSB Rocky Top Solutions, LLC providing custom website and mobile app development services, SEO services, and technology consulting.

Technology Today

Tutorials on software development, analytics, web and mobile development, SEO, and other technology related tutorials

Corey Walker

Written by

Owner of SDVOSB Rocky Top Solutions, LLC providing custom website and mobile app development services, SEO services, and technology consulting.

Technology Today

Tutorials on software development, analytics, web and mobile development, SEO, and other technology related tutorials

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store