Package: lsi
## LSIThe `lsi` command provides an easy way to rapidly query AWS to find informationabout an instance, SSH onto it, or run an SSH command on multiple hosts inparallel.#### Instance searchSearching for an instance is exceedingly easy. Simply type `lsi` followed byzero or more filters, which are substrings of an instance's name, IP address,or other identifying information:```> lsi stg database+---------------------------------------|-----------+| Instance Name                         | Public IP || database-data-stg-1                   | 10.0.1.2  || database-data-stg-2                   | 10.0.1.2  || database-data-stg-3                   | 10.0.1.2  || database-services-stg-1               | 10.0.1.2  || database-services-stg-2               | 10.0.1.2  || database-services-stg-3               | 10.0.1.2  || stg-database-config-server-i-153dc5e9 | 10.0.1.2  || stg-database-config-server-i-1d21dcf5 | 10.0.1.2  || stg-database-config-server-i-2bd0d1c5 | 10.0.1.2  |+---------------------------------------|-----------+```You can provide exclusionary filters with `-v`:```> lsi stg database -v services+---------------------------------------|-----------+| Instance Name                         | Public IP || database-rs-data-stg-1                | 10.0.1.2  || database-rs-data-stg-2                | 10.0.1.2  || database-rs-data-stg-3                | 10.0.1.2  || stg-database-config-server-i-153dc5e9 | 10.0.1.2  || stg-database-config-server-i-1d21dcf5 | 10.0.1.2  || stg-database-config-server-i-2bd0d1c5 | 10.0.1.2  |+---------------------------------------|-----------+```The table by default will consist only of machine names and public IPs. Youcan pull up additional information by passing the `--show` argument:```> lsi stg database --show private_ip+---------------------------------------|-----------|------------+| Instance Name                         | Public IP | Private IP || database-rs-data-stg-1                | 10.0.1.2  | 10.0.1.2   || database-rs-data-stg-2                | 10.0.1.2  | 10.0.1.2   || database-rs-data-stg-3                | 10.0.1.2  | 10.0.1.2   || database-rs-services-stg-1            | 10.0.1.2  | 10.0.1.2   || database-rs-services-stg-2            | 10.0.1.2  | 10.0.1.2   || database-rs-services-stg-3            | 10.0.1.2  | 10.0.1.2   || stg-database-config-server-i-153dc5e9 | 10.0.1.2  | 10.0.1.2   || stg-database-config-server-i-1d21dcf5 | 10.0.1.2  | 10.0.1.2   || stg-database-config-server-i-2bd0d1c5 | 10.0.1.2  | 10.0.1.2   |+---------------------------------------|-----------|------------+```You can see all of the things that are available to show by requesting`--attributes`:```> lsi --attributesThe following attributes are available: logical_id, ami_id, name, tags, stack_name, hostname, launch_time, public_ip, instance_type, private_ip, stack_id, security_groups```#### SSH onto an instanceOften the reason for searching in the first place is to SSH onto one of theinstances you find. Rather than copy/pasting manually, you can do this directlyfrom `lsi` using the `--ssh` or `-s` flag:```> lsi -s stg database data+---|---------------------|-------------------------------------------|---------------+|   | Instance Name       | Hostname                                  | Public IP     || 0 | database-data-stg-1 | ec2-W-X-Y-Z.compute-1.amazonaws.com       | 10.0.1.2      || 1 | database-data-stg-2 | ec2-W-X-Y-Z.compute-1.amazonaws.com       | 10.0.1.2      || 2 | database-data-stg-3 | ec2-W-X-Y-Z.compute-1.amazonaws.com       | 10.0.1.2      |+---|---------------------|-------------------------------------------|---------------+3 matching entries.Commands:<n>: Connect to the nth instance in the listu username: Change SSH username to username (currently none set)i idfile: Change identity file to idfile (currently none set)f <one or more patterns>: Restrict results to those with patternse <one or more patterns>: Restrict results to those without patternsc <command>: Set ssh command to run on matching hosts (currently none set)x: Execute the above command on the above host(s)q: QuitEnter command:```At this point, you can enter the number of the instance you want to SSH onto,which will immediately SSH you onto a machine.Of course, you might not have permissions onto a machine with your ownusername, or you might want to log in as another user or with a specificidentity file. You can do this with `--username` (`-u`) and `--identity-file`(`-i`), respectively. If you do this, you don't need to pass the `-s` flag.```> lsi -u someuser -i ~/.ssh/somekey.pem stg database data+---|---------------------|-------------------------------------------|---------------+|   | Instance Name       | Hostname                                  | Public IP     || 0 | database-data-stg-1 | ec2-W-X-Y-Z.compute-1.amazonaws.com       | 10.0.1.2      || 1 | database-data-stg-2 | ec2-W-X-Y-Z.compute-1.amazonaws.com       | 10.0.1.2      || 2 | database-data-stg-3 | ec2-W-X-Y-Z.compute-1.amazonaws.com       | 10.0.1.2      |+---|---------------------|-------------------------------------------|---------------+3 matching entries.Commands:<n>: Connect to the nth instance in the listu username: Change SSH username to username (currently someuser)i idfile: Change identity file to idfile (currently /home/anelson/.ssh/somekey.pem)f <one or more patterns>: Restrict results to those with patternse <one or more patterns>: Restrict results to those without patternsc <command>: Set ssh command to run on matching hosts (currently none set)x: Execute the above command on the above host(s)q: QuitEnter command:```#### Running SSH commands across instancesYou can use `lsi` to execute an SSH command remotely on one or more instances.To do this, use the `--command` (`-c`) option. Enter `x` at the confirmationscreen.```> lsi -c hostname stg database data+---|---------------------|-------------------------------------------|---------------+|   | Instance Name       | Hostname                                  | Public IP     || 0 | database-data-stg-1 | ec2-W-X-Y-Z.compute-1.amazonaws.com       | 10.0.1.2      || 1 | database-data-stg-2 | ec2-W-X-Y-Z.compute-1.amazonaws.com       | 10.0.1.2      || 2 | database-data-stg-3 | ec2-W-X-Y-Z.compute-1.amazonaws.com       | 10.0.1.2      |+---|---------------------|-------------------------------------------|---------------+3 matching entries.Commands:<n>: Connect to the nth instance in the listu username: Change SSH username to username (currently none set)i idfile: Change identity file to idfile (currently none set)f <one or more patterns>: Restrict results to those with patternse <one or more patterns>: Restrict results to those without patternsc <command>: Set ssh command to run on matching hosts (currently hostname)x: Execute the above command on the above host(s)q: QuitEnter command: xRunning command `hostname` on 3 matching hosts[database-data-stg-2 (10.0.1.2)]: ip-10.0.1.2[database-data-stg-3 (10.0.1.2)]: ip-10.0.1.2[database-data-stg-1 (10.0.1.2)]: ip-10.0.1.2All commands finished```#### ProfilesIt can be a bit tedious to enter extensive command-line arguments, especiallyif they are the same over and over again. To alleviate this, you can create*profiles* for LSI, which are collections of configuration. For example, youcan create a `someuser` profile which uses the `someuser` username and appropriatekeyfile. To do this, add a section to `.lsi`, which is written in the `ini`format. For example:```ini[someuser]username=someuseridentity file=~/.ssh/somekey.pem```You can then invoke your profile with `--profile` (`-p`):```> lsi -p someuser stg database data+---|---------------------|-------------------------------------------|---------------+|   | Instance Name       | Hostname                                  | Public IP     || 0 | database-data-stg-1 | ec2-W-X-Y-Z.compute-1.amazonaws.com       | 10.0.1.2      || 1 | database-data-stg-2 | ec2-W-X-Y-Z.compute-1.amazonaws.com       | 10.0.1.2      || 2 | database-data-stg-3 | ec2-W-X-Y-Z.compute-1.amazonaws.com       | 10.0.1.2      |+---|---------------------|-------------------------------------------|---------------+3 matching entries.Commands:<n>: Connect to the nth instance in the listu username: Change SSH username to username (currently someuser)i idfile: Change identity file to idfile (currently /home/anelson/.ssh/somekey.pem)f <one or more patterns>: Restrict results to those with patternse <one or more patterns>: Restrict results to those without patternsc <command>: Set ssh command to run on matching hosts (currently none set)x: Execute the above command on the above host(s)q: QuitEnter command:```Profiles can inherit from other profiles, allowing you to avoid repetition. Forexample, you might put the entire above command into a profile:```ini[someuser]username=someuseridentity file=~/.ssh/somekey.pem[stg-database]inherits=someuserfilters=stg,database,data```Then the `lsi -p stg-database` command will be equivalent to the above.## Installation#### Via `pip`:```bash$ pip install lsi```