Deploying to AWS lambdas to multiple regions in one go

Building [uptime monitoring](https://httpscop.com) in https cop required me to deploy lambdas to multiple regions and this is my first introduction to the serverless world. I know of a very handy tool [Up](https://github.com/apex/up) to deploy to AWS Lambdas using a CLI without any hassle at all but it doesn’t support deploying to multiple regions at the time of writing (`Up version v0.5.0`).

After exchanging a few tweets with [TJ](https://twitter.com/tjholowaychuk) (creator of Up) I got to know I can specify `AWS_REGION` as an environment variable while calling Up and that will do the trick. Simply put, instead of defining regions in your `up.json` file, you can specify it at the time of invoking the command, like `AWS_REGION=us-east-1 up`.

So, one can (I did) write a bash script to do the deployments to all regions they desire at will.

Here is a quick [list of all regions](https://docs.aws.amazon.com/general/latest/gr/rande.html) where you can deploy with AWS Lambda:

US East (Ohio) us-east-2
US East (N. Virginia) us-east-1
US West (N. California) us-west-1
US West (Oregon) us-west-2
Asia Pacific (Tokyo) ap-northeast-1
Asia Pacific (Seoul) ap-northeast-2
Asia Pacific (Mumbai) ap-south-1
Asia Pacific (Singapore) ap-southeast-1
Asia Pacific (Sydney) ap-southeast-2
Canada (Central) ca-central-1
China (Beijing) cn-north-1
EU (Frankfurt) eu-central-1
EU (Ireland) eu-west-1
EU (London) eu-west-2
EU (Paris) eu-west-3
South America (Sao Paulo) sa-east-1

Pick the locations and make changes in the following bash script (remove or comment out the regions that you don’t want):

#!/usr/bin/env bash
declare -a regions=(
us-east-2 #US East (Ohio)
us-east-1 #US East (N. Virginia)
us-west-1 #US West (N. California)
us-west-2 #US West (Oregon)
ap-northeast-1 #Asia Pacific (Tokyo)
ap-northeast-2 #Asia Pacific (Seoul)
ap-south-1 #Asia Pacific (Mumbai)
ap-southeast-1 #Asia Pacific (Singapore)
ap-southeast-2 #Asia Pacific (Sydney)
ca-central-1 #Canada (Central)
cn-north-1 #China (Beijing)
eu-central-1 #EU (Frankfurt)
eu-west-1 #EU (Ireland)
eu-west-2 #EU (London)
eu-west-3 #EU (Paris)
sa-east-1 #South America (Sao Paulo)
)
for region in “${regions[@]}”
do
echo “Deploying to $region”
AWS_REGION=$region up
echo “Deployed: ” $(AWS_REGION=$region up url)
echo # echo new line
done

Hope that helps you ship!

P.S. – If you need all AWS Lambdas plotted on a map to see their geographical location, here you go:

AWS lambdas marked on a map
AWS lambdas marked on a map

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *