Deploying Serverless into Different Stages and Regions

...
  • Serverless
About 3 min

# Deploying Serverless into Different Stages and Regions

# What are the stages and regions

Most of the companies deploy their software into multiple environments for different purposes. A development environment can be used for development and a staging environment can be used for pre-production testing as an example. Serverless Framework provides two mechanisms for deploying your Serverless Infrastructure into different environments. They are stages and regions.

# Deploying into Different Regions

The easiest solution to keep your environments separate is to deploy each environment into a different region. The advantage of this approach is that it's simple. All you need to do is to switch your region and hit deploy. You can apply some additional IAM rules based on the regions that isolate one environment from another.

On another hand, deploying into a different region is limited. There are only so many regions available. In addition to it, if your region is located far from your users, you can introduce some unnecessary latency that can hurt some user experience.

# Setting Up the Project

Let's deploy our sample project with just one tankHandler lambda into multiple regions. Download or clone our Open Source repo. Run yarn install or npm install in sample-apps/serverless-lambda to install the necessary plugins. Next, open Commandeer, choose Serverless -> Runner from the side navigation and choose your serverless.yml file under the folder sample-apps/serverless-lambda.

Choosing the serverless.yml file

# Deploying to the West Side or the East Side

If you haven't done so yet, you'll need to set up your AWS connection by following our getting started guide. If you already have your AWS connection set up, let's dive in straight into the deployment action.

Choose N. Virginia (aka us-east-1) from the region dropdown. Doing so will set our deployment to go to the East. Also, feel free to choose the region you like, we're just using us-east-1 as an example here. Next, click deploy, which deploys your Serverless function to the Eastside.

Once the deployment is finished, you can switch your region to the west (for instance us-west-1) and hit deploy. Now you have your lambda on the West too.

Serverless deployed to the West

Feel free to navigate to the Lambda section to verify the lambdas in each region you deployed it to.

Tips

Join our email Newsletter to receive some amazing Cloud Development articles in your inbox.

# Using Different Stages

Deploying your lambdas using different stages is far more flexible. As long as you're using a different name for your stage, you can deploy as many variations of your lambdas as you like. Using stages will also put the name of your stage into the name of the lambda itself. It helps you to avoid some naming collisions in the same region or account.

# Setting Up Your Stage

Setting up your stage is quite straightforward. Open Commandeer, go to Serverless -> Runner using the side navigation. Click on the gear icon to bring up Serverless settings. Scroll down to the stage text field and enter the name of your stage. For this tutorial, we'll choose the stage named dev.

Entering a Serverless stage name

# Deploying to the dev Stage

Next, just click the Deploy button to deploy your lambda using the dev stage. Once the deployment is over, go to the Lambda page from the side navigation and see your newly deployed lambda. As you can see, Serverless also put the stage name into the Lambda name itself to avoid some naming collisions.

The stage name is in the name of the lambda

# Conclusion

Serverless Framework provides you with the ability to deploy your Serverless infrastructure into different regions and using different stages. Deploying into multiple regions is a great solution for some simple use-cases. Stage based deployment is more flexible which fits perfectly for more complicated use-cases. You can also combine both approaches by using different stages and different regions to maximize environment isolation and to avoid some naming collisions. Commandeer supports both of the deployment options making you more productive at developing for the cloud. Go ahead and give it a shot for your Serverless project.

Download Commandeer App

Last update: August 2, 2020 05:58