This command line tool is designed to help people interact with different sets of AWS profiles and EC2 instances. It allows you to easily switch between multiple sets of AWS credentials and perform the following operations:
- list EC2 instances on the account, optionally filtered by a "Lane" tag.
- quickly SSH into a specific EC2 instance using the correct credentials, optionally setting up tunnels to locally access services running on a given instance.
- copy files to all EC2 instances in a given lane
- run commands on all EC2 instances in a given lane
$ lanes ls
Current profile: foo
Fetching servers... done
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ AWS Servers โ
โโโโโโโฌโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโโโโค
โ IDX โ LANE โ SERVER โ IP ADDRESS โ STATE โ ID โ
โโโโโโโผโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโค
โ 1 โ dev โ dev-01 โ 1.2.3.4 โ running โ i-12341234 โ
โ 2 โ uat โ uat-01 โ 1.2.3.5 โ running โ i-12341235 โ
โ 3 โ prod โ prod-01 โ 1.2.3.6 โ running โ i-12341236 โ
โ 4 โ prod โ prod-02 โ 1.2.3.7 โ running โ i-12341237 โ
โฐโโโโโโดโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโโฏ
$ lanes ls dev
Current profile: foo
Fetching servers... done
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ AWS Servers โ
โโโโโโโฌโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโโโโค
โ IDX โ LANE โ SERVER โ IP ADDRESS โ STATE โ ID โ
โโโโโโโผโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโค
โ 1 โ dev โ dev-01 โ 1.2.3.4 โ running โ i-12341234 โ
โฐโโโโโโดโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโโฏ
$ lanes ls prod
Current profile: foo
Fetching servers... done
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ AWS Servers โ
โโโโโโโฌโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโโโโค
โ IDX โ LANE โ SERVER โ IP ADDRESS โ STATE โ ID โ
โโโโโโโผโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโค
โ 1 โ prod โ prod-01 โ 1.2.3.6 โ running โ i-12341236 โ
โ 2 โ prod โ prod-02 โ 1.2.3.7 โ running โ i-12341237 โ
โฐโโโโโโดโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโโฏ
A lane is basically a logical environment for your EC2 instances. For example, you could have a lane called "dev" for development servers, one called "uat" user acceptance testing, and one called "prod" for production servers.
- Download a pre-compiled, released version from the releases page
- Mark the binary as executable
- Move the binary to your
$PATH
For example:
$ curl -Lo /tmp/lanes https://github.com/codekoala/go-aws-lanes/releases/download/v0.4.1/lanes_linux_amd64
$ chmod +x /tmp/lanes
$ sudo mv /tmp/lanes /usr/local/bin/lanesTo compile from source, please see the instructions in the contributing section.
There is a PKGBUILD in the AUR
to help package and install lanes for Arch Linux-based distributions.
As of v0.2.1, initial configuration is handled the first time you run any lanes
command. You may also use the lanes init command.
# initialize a lanes and create a sample lanes profile
$ lanes init
# initialize a lanes and but do not create a sample lanes profile
$ lanes init --no-profile
# initialize a lanes, overwriting any existing lanes configuration (the
# "default" lanes profile will NOT be overwritten if it exists)
$ lanes init --forceAlternatively, you may copy the $HOME/.lanes/ directory from another system
where you have previously configured lanes.
lanes includes a helper to create fresh lane profiles:
# create a new profile, prompting for the profile name and AWS credentials
$ lanes init profile
# create a new profile named "foo", prompting only for the AWS credentials
$ lanes init profile foo
# create a new profile named "foo" with "ABCD" as the AWS Access Key ID,
# prompting only for the AWS Secret Access Key
$ lanes init profile foo ABCDProfiles created with this command will include examples for how to configure
individual lanes. lanes automatically switches to profiles created with
this command. If you would like to create a new profile without switching to it
immediately, use the --no-switch or -n flags:
# create a new profile named "foo", prompting only for the AWS credentials,
# without automatically switching to the new profile
$ lanes init profile foo --no-switchlanes includes a helper to quickly open the configuration for a specific
profile in your default editor. Your default editor is determined by the
$EDITOR environment variable. If this variable is not set, lanes attempts
to use vi.
# edit your current profile using your default editor
$ lanes edit
# edit the profile called "foo" using your default editor
$ lanes edit fooWhen executing lanes, the desired profile is determined first by the
LANES_PROFILE environment variable. If this is not set, the profile
configured in $HOME/.lanes/lanes.yml will be used.
If you wish to quickly change your default profile, you may use lanes switch [new profile name].
Examples:
# override current profile for a single invocation
$ LANES_PROFILE=demo lanes ls
# override current profile for the rest of the terminal session
$ export LANES_PROFILE=demo
$ lanes ls
# set the default profile to $HOME/.lanes/home-profile.yml
$ lanes switch home-profileExamples:
# list all instances for the current profile
$ lanes list
$ lanes ls
# list all instances in the "prod" lane for the current profile
$ lanes list prod
$ lanes ls prodAs of version 0.3.0, the list/ls command has a --batch/-b option to
disable table headers and borders for easier use with batch operations. It is
also possible to show specific columns with the --columns/-c option.
Alternatively, specific columns may be hidden using the --hide option.
Using the list command in batch mode can be helpful when writing other
scripts to interact with your AWS EC2 instances. For example, here's a
one-liner to produce a roster for salt-ssh:
$ lanes ls -c SSH_IDENTITY,USER,IP,NAME | \
sed "s,~,$HOME,g" | \
awk '/\.pem/ { \
print $4":\n \
host: "$3"\n \
user: "$2"\n \
sudo: true\n \
tty: true\n \
priv: "$1"\n \
"}' > /etc/salt/rosterAs of version 0.4.0, the list/ls command also supports dumping the server
table in CSV format using the --csv argument.
Examples:
# list all instances, prompting for the instance to connect to
$ lanes ssh
# list all instances in the "prod" lane, prompting for the instance to connect to
$ lanes ssh prodExamples:
# list all instances in the "prod" lane, confirming before executing the
# specified command on each instance
$ lanes sh prod 'ls -l'
# list all instances in the "prod" lane, executing the specified command on
# each instance without confirmation
$ lanes sh prod --confirm 'ls -l'As of version 0.4.0, lanes sh supports running the specified command on
multiple machines in parallel. There are three different options to enable
parallel execution:
--parallelruns the specified command on all instances in the specified lane at the same time.--num-parallel/-n Nruns the specified command on up toNinstances in the specified line at the same time.--pparallel Nruns the specified command on up toN%of the instances in the specified lane at the same time.
As of version 0.4.1, the command for lanes sh does not require quotes (though
that's still permitted). Commands can be specified after -- as such:
# list all instances in the "prod" lane, confirming before executing the
# specified command on each instance
$ lanes sh prod -- ls -l
# list all instances in the "prod" lane, executing the specified command on
# each instance without confirmation
$ lanes sh prod --confirm -- ls -lExamples:
# list all instances in the "dev" lane, confirming before copying localfile.txt
# to /tmp/localfile.txt on all instances
$ lanes file push dev localfile.txt /tmp/
# list all instances in the "dev" lane, confirming before copying localfile.txt
# and magic.log to /tmp/ on all instances
$ lanes file push dev localfile.txt magic.log /tmp/
# list all instances in the "dev" lane, copying localfile.txt and magic.log to
# /tmp/ on all instances without confirmation
$ lanes file push dev --confirm localfile.txt magic.log /tmp/The configuration for this tool lives in $HOME/.lanes/ by default. There
are two forms of configuration for lanes: the configuration for lanes
itself and configuration for individual lanes in their respective files.
The configuration for lanes itself lives in $HOME/.lanes/lanes.yml by
default. Here are the configuration options:
profile: default
region: us-west-2
disable_utf8: false
tags:
name: Name
lane: Laneprofile: default: this indicates that the "lane profile" should be read from$HOME/.lanes/default.yml.region: us-west-2: this is the default AWS region to use when querying EC2 instances.disable_utf8: false: this setting can be used to toggle UTF-8 and ASCII mode for table borders.tags.name: Name: this indicates that the EC2 instance tag named "Name" will be used to determine each instance's name. Change this if you use a different tag name in your environment.tags.lane: Lane: this indicates that the EC2 instance tag named "Lane" will be used to determine each instance's lane. Change this if you use a different tag name in your environment.
The configuration for an individual lane lives in $HOME/.lanes/[lane profile name].yml by default. Here are the configuration options:
aws_profile: FADS
aws_access_key_id: ASDF
aws_secret_access_key: FDSA
region: us-east-1
ssh:
mods:
dev:
identity: ~/.ssh/id_rsa_dev
tunnels:
- 8080:127.0.0.1:80
- 3306:127.0.0.1:3306
uat:
identity: ~/.ssh/id_rsa_uat
tunnel: 8080:127.0.0.1:80
prod:
identity: ~/.ssh/id_rsa_prodaws_profile: the AWS profile to use from~/.aws/credentials. This does not take precedence overaws_access_key_idandaws_secret_access_key.aws_access_key_id: the AWS access key ID for the lane profile.aws_secret_access_key: the AWS secret access key for the lane profile.region: the default region for this lane profile. If not specified, the region will be determined by the global configuration forlanes(see above).ssh.mods.[lane name].user: the username to use when SSH'ing into an EC2 instance in the specified lane.ssh.mods.[lane name].identity: the private key to use when SSH'ing into instances in the specified lane.ssh.mods.[lane name].tunnel: a single tunnel to setup when SSH'ing to a specific EC2 instance in the specified lane.ssh.mods.[lane name].tunnels: a list of tunnels to setup when SSH'ing to a specific EC2 instance in the specified lane.
lanes supports a handful of environment variables to quickly change
behavior:
LANES_CONFIG_DIR: the directory where all configuration is expected to reside. Default:$HOME/.lanes/LANES_CONFIG: the configuration file to use for lanes. Default:$LANES_CONFIG_DIR/lanes.ymlLANES_REGION: the AWS region to use when listing EC2 instances. Default:us-west-2LANES_DISABLE_UTF8: set this to any value to use ASCII for table borders. UTF-8 borders are enabled by default.LANES_TAG_LANE: the EC2 instance tag to use for determining which lane an instance belongs to. Default:LaneLANES_TAG_NAME: the EC2 instance tag to use for determining an instance's name. Default:Name
To build and install lanes locally, you will need to have Go
1.8 or newer, as well as Glide to
manage the build dependencies.
Clone the repository:
$ git clone https://github.com/codekoala/go-aws-lanes.gitInstall dependencies:
$ glide installBuild the binary:
# for Linux systems
$ make linux
# for OSX systems
$ make osx
# for both Linux and OSX
$ makeThe resulting binaries will appear as ./bin/lanes_$GOOS_$GOARCH.
If you just want to run the tests:
$ make testIf you wish to contribute changes to the project, please fork the repository, make the changes in your fork, and submit a pull request.
This project is heavily based on https://github.com/Lemniscate/aws-lanes. The main reason for building this version was to ease the burden of installing the utility on different platforms.