Useful cli tools for Amazon EC2.
- How to install and settings
- Usage
- Options
- Combination example of the peco command
- Contribution
- License
$ go get -u github.com/ohsawa0515/ec2-toys
Please ignore if you use IAM Roles.
- Credential file (
$HOME/.aws/credentials
)
[default]
aws_access_key_id = <YOUR_ACCESS_KEY_ID>
aws_secret_access_key = <YOUR_SECRET_ACCESS_KEY>
If you want to use profile, and set as follows.
[default]
aws_access_key_id = <YOUR_ACCESS_KEY_ID>
aws_secret_access_key = <YOUR_SECRET_ACCESS_KEY>
[dev]
aws_access_key_id = <YOUR_ACCESS_KEY_ID>
aws_secret_access_key = <YOUR_SECRET_ACCESS_KEY>
- Environment variable
$ export AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY_ID
$ export AWS_SECRET_ACCESS_KEY=YOUR_SECRET_ACCESS_KEY
- shared config (
$HOME/.aws/config
)
[default]
region = us-east-1
If you want to use profile, and set as follows.
[default]
region = us-east-1
[dev]
region = us-east-1
- Environment variable
$ export AWS_REGION=us-east-1
After run ec2-toys list
, listing ec2 instances.
$ ec2-toys list
admin-server 192.0.2.11 203.0.113.11 i-xxxxxxxx c3.large us-east-1c running linux
batch-server001 192.0.2.20 203.0.113.20 i-xxxxxxxx t2.medium us-east-1c running windows
web-server001 192.0.2.12 203.0.113.12 i-xxxxxxxx t2.micro us-east-1a running linux
web-server002 192.0.2.13 203.0.113.13 i-xxxxxxxx t2.medium us-east-1c stopped linux
Support --filter
option like describe-instances command.
# Running instances.
$ ec2-toys list --filters "Name=instance-state-name,Values=running"
admin-server 192.0.2.11 203.0.113.11 i-xxxxxxxx c3.large us-east-1c running linux
batch-server001 192.0.2.20 203.0.113.20 i-xxxxxxxx t2.medium us-east-1c running windows
web-server001 192.0.2.12 203.0.113.12 i-xxxxxxxx t2.micro us-east-1a running linux
# Instance type is t2.medium
$ ec2-toys list --filters "Name=instance-type,Values=t2.medium"
batch-server001 192.0.2.20 203.0.113.20 i-xxxxxxxx t2.medium us-east-1c running windows
web-server002 192.0.2.13 203.0.113.13 i-xxxxxxxx t2.medium us-east-1c stopped linux
# Running and t2.medium instances(Separate by space).
$ ec2-toys list --filters "Name=instance-state-name,Values=running Name=instance-type,Values=t2.medium"
batch-server001 192.0.2.20 203.0.113.20 i-xxxxxxxx t2.medium us-east-1c running windows
The region to use. Overrides config/env settings.
e.g.
$ ec2-toys list --region ap-northeast-1 # Tokyo region
Use a specific profile from your credential file. See cli-multiple-profiles.
e.g.
# If you have the following settings,
[dev]
aws_access_key_id = <YOUR_ACCESS_KEY_ID>
aws_secret_access_key = <YOUR_SECRET_ACCESS_KEY>
# You use profile dev.
$ ec2-toys list --profile dev
Filtering EC2 instances.
e.g.
# Running instances.
$ ec2-toys list --filters "Name=instance-state-name,Values=running"
# Instance type is t2.medium
$ ec2-toys list --filters "Name=instance-type,Values=t2.medium"
# Running and t2.medium instances(Separate by space).
$ ec2-toys list --filters "Name=instance-state-name,Values=running Name=instance-type,Values=t2.medium"
# Specify VPC ID
$ ec2-toys list --filters "Name=vpc-id,Values=vpc-xxxxxxxx"
# Filter instances with a Env=prod tag
$ ec2-toys list --filters "Name=tag:Env,Values=prod"
peco is Simplistic interactive filtering tool. Combined with peco command, you cloud be conveniently SSH.
$ alias ssh-ec2="ec2-toys list --filters \"Name=instance-state-name,Values=running\" | grep linux | peco | awk {'print \$3'} | xargs -I{} sh -c 'ssh ec2-user@{} < /dev/tty' ssh"
Refer to http://qiita.com/kawaz/items/a0151d3aa2b6f9c4b3b8 .
# ~/.ssh/config
Host bastion-server/*
ProxyCommand ssh -W "$(basename "%h")":%p "$(dirname "%h")"
Host bastion-sever
Hostname xxx.xxx.xxx.xxx
User foo
IdentityFile ~/.ssh/id_rsa
$ alias ssh-bastion="ec2-toys list --filters \"Name=instance-state-name,Values=running\" | grep linux | peco | awk {'print \$2'} | xargs -I{} sh -c 'ssh bastion-server/{} < /dev/tty' ssh"
- Fork (https://github.com/ohsawa0515/ec2-toys/fork)
- Create a feature branch
- Commit your changes
- Rebase your local changes against the master branch
- Run test suite with the
go test ./...
command and confirm that it passes - Run
gofmt -s
- Create new Pull Request
See LICENSE.