Warning: Just a quick prototype. May behaves strange / like an asshole.
SSH into EC2 instances via tags. More or less an exact copy of facebookarchive/ec2-ssh.
$ npm install -g ec2ssh
The module uses the AWS JavaScript SDK internally, so please take a look at: http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html
By default, ec2ssh will automatically use the shared credentials file (~/.aws/credentials
) for configuration when loading.
[default]
output = json
region = eu-west-1
aws_access_key_id = your_aws_access_key_id
aws_secret_access_key = your_aws_secret_access_key
$ ec2hosts
.--------------------------------------------------------------------------------------.
| Name | DNS |
|---------------------------------|----------------------------------------------------|
| foo-instance | ec2-xx-xx-xx-xxx.eu-west-1.compute.amazonaws.com |
| bar-instance | ec2-xx-xx-xx-xxx.eu-west-1.compute.amazonaws.com |
| baz-instance | ec2-xx-xx-xx-xxx.eu-west-1.compute.amazonaws.com |
'--------------------------------------------------------------------------------------'
$ ec2hosts foo
.--------------------------------------------------------------------------------------.
| Name | DNS |
|---------------------------------|----------------------------------------------------|
| foo-instance | ec2-xx-xx-xx-xxx.eu-west-1.compute.amazonaws.com |
'--------------------------------------------------------------------------------------'
$ ec2hosts bar baz
.--------------------------------------------------------------------------------------.
| Name | DNS |
|---------------------------------|----------------------------------------------------|
| bar-instance | ec2-xx-xx-xx-xxx.eu-west-1.compute.amazonaws.com |
| baz-instance | ec2-xx-xx-xx-xxx.eu-west-1.compute.amazonaws.com |
'--------------------------------------------------------------------------------------'
$ ec2hosts -h
Usage: ec2hosts [options] <nameFilter1, nameFilter2, ...>
Options:
-h, --help output usage information
-V, --version output the version number
-k, --aws-key [key] Amazon Access Key. Defaults to ~/.aws/credentials -> aws_access_key_id or ENV.AWS_ACCESS_KEY_ID
-s, --aws-secret [secret] Amazon Secret Access Key. Defaults to ~/.aws/credentials -> aws_secret_access_key or ENV.AWS_SECRET_ACCESS_KEY
-r, --region [region] Amazon EC2 Region. Defaults to `eu-west-1` or ENV.AWS_EC2_REGION
-t, --tag [tag] Tag name for searching. Defaults to `Name`
$ ec2ssh ba
? Please select an instance to connect to: (Use arrow keys)
❯ bar-instance
baz-instance
[Enter]
Welcome to Ubuntu 12.04.5 LTS (GNU/Linux 3.2.0-76-virtual x86_64)
System information as of Thu Feb 26 09:47:32 UTC 2015
System load: 0.0 Processes: 64
Usage of /: 29.7% of 7.87GB Users logged in: 0
Memory usage: 8% IP address for eth0: 10.82.154.32
Swap usage: 0%
0 packages can be updated.
0 updates are security updates.
ubuntu@bar.instance.com: ~
→ ls
tmp foo
→ exit
logout
Connection to ec2-xx-xx-xx-xxx.eu-west-1.compute.amazonaws.com closed.
[ec2ssh] - SSH connection closed!
$ ec2ssh bar-instance
[ec2ssh] - Connecting to bar-instance ...
Welcome to Ubuntu 12.04.5 LTS (GNU/Linux 3.2.0-76-virtual x86_64)
System information as of Thu Feb 26 09:47:32 UTC 2015
System load: 0.0 Processes: 64
Usage of /: 29.7% of 7.87GB Users logged in: 0
Memory usage: 8% IP address for eth0: 10.82.154.32
Swap usage: 0%
0 packages can be updated.
0 updates are security updates.
ubuntu@bar.instance.com: ~
→ ls
tmp foo
→ exit
logout
Connection to ec2-xx-xx-xx-xxx.eu-west-1.compute.amazonaws.com closed.
[ec2ssh] - SSH connection closed!
$ ec2ssh -h
Usage: ec2ssh [options] <nameFilter1, nameFilter2, ...>
Options:
-h, --help output usage information
-V, --version output the version number
-k, --aws-key [key] Amazon Access Key. Defaults to ~/.aws/credentials -> aws_access_key_id or ENV.AWS_ACCESS_KEY_ID
-s, --aws-secret [secret] Amazon Secret Access Key. Defaults to ~/.aws/credentials -> aws_secret_access_key or ENV.AWS_SECRET_ACCESS_KEY
-r, --region [region] Amazon EC2 Region. Defaults to `eu-west-1` or ENV.AWS_EC2_REGION
-t, --tag [tag] Tag name for searching. Defaults to `Name`
-u, --user [user] User used for ssh connection. Defaults to `ubuntu`
- Use all available command line options
- Tests
- Proper error handling
Inspired by Instagram Engineering Blog / Simplifying EC2 SSH Connections
(The MIT License)
Copyright (c) 2015 Dominik Lessel dominik@mifitto.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.