If your AWS resources are spread across multiple Regions, there is a simple trick to save you adding the –region=REGION parameter after each time your are issuing AWS EC2 API commands.

store your settings in a file e.g. ~/.ec2/eu-settings

export EC2_URL=https://ec2.eu-west-1.amazonaws.com
export EC2_REGION=eu-west-1

and e.g. ~/.ec2/us-settings

export EC2_URL=https://ec2.us-east-1.amazonaws.com
export EC2_REGION=us-east-1

now we define two simple aliases as shortcuts to these settings.

# alias eu=’source ~/.ec2/eu-settings’
# alias us=’source ~/.ec2/us-settings’

calling ‘eu’ or ‘us’ from shell will now switch the regions for you.

you may check that it worked by typing env and noting the values for EC2_URL and EC2_REGION.

These two aliases will – for now – only work in your current login session. To persist the setting, just do the following…

Persisting the aliases in /etc/bash.bashrc

edit /etc/bash.bashrc (in debian – this might differ a bit in other linux distributions)

# vi /etc/bash.bashrc

add

alias eu=’source ~/.ec2/eu-settings’
alias us=’source ~/.ec2/us-settings’

below anything that is written there. And call

# source /etc/bash.bashrc

The aliases should work as previously, but will now be available after a system restart or new login to your machine.

Check again using env if you want to verify everything worked correctly.

Inspiration taken from: http://learninginlinux.blogspot.com/2007/02/setting-environment-variables-through.html