cloudpack佐藤です。

ec2ctl

y13iさんが制作しているAWSツール。

File: README— Documentation for ec2ctl (0.2.1)

EC2 インスタンスの一覧表示、Start、Stop、タグ確認などが行え、
MITライセンスで使用が可能。

Copyright (c) 2014 y13i

準備

不足パッケージを追加する。

sudo xcodebuild -license
gem install json -v '1.8.1'

ec2ctlインストール

Gamfile作成

#vim Gemfile
====
source 'https://rubygems.org'
gem 'ec2ctl'
====

bundle

#bundle install
====
Installing nokogiri 1.6.3.1
Installing aws-sdk-v1 1.53.0
Installing aws-sdk 1.53.0
Installing aws_config 0.0.2
Installing colorize 0.7.3
Installing net-ssh 2.9.1
Installing terminal-table 1.4.5
Installing thor 0.19.1
Installing unindent 1.0
Installing ec2ctl 0.3.0
Using bundler 1.6.5
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
====

確認

# ec2ctl

Commands:
  ec2ctl add NAME ELB_NAME     # Add instance to ELB. Instance will be searched by Name tag.
  ec2ctl help [COMMAND]        # Describe available commands or one specific command
  ec2ctl lb ELB_NAME           # Show load balancer registered instance statuses.
  ec2ctl list PATTERN          # List all instances in region. Specify PATTERN to filter results by name.
  ec2ctl remove NAME ELB_NAME  # Remove instance from ELB. Instance will be searched by Name tag.
  ec2ctl ssh NAME COMMAND      # Execute remote command to specified instance by given name.
  ec2ctl start NAME            # Start instance. Instance will be searched by Name tag.
  ec2ctl status NAME           # Show instance status. Instance will be searched by Name tag.
  ec2ctl stop NAME             # Stop instance. Instance will be searched by Name tag.

Options:
  k, [--access-key-id=ACCESS_KEY_ID]
  s, [--secret-access-key=SECRET_ACCESS_KEY]
  r, [--region=REGION]
      [--profile=PROFILE]
      [--color], [--no-color]
                                              # Default: true

使用方法

credential用意

 vim .aws/credentials

[test]
aws_access_key_id=XXXXXXXXXXXXXXXXXXXX
aws_secret_access_key=XXXXXXXXXXXXXXXXXX

インスタンス一覧

ec2ctl list  --profile=test --region=ap-northeast-1

+------------+-------------------+------------+---------------+---------------+---------+
| ID         | Name              | Type       | Private IP    | Public IP     | Status  |
+------------+-------------------+------------+---------------+---------------+---------+
| i-xxxxxxxx | hoge              | m3.xlarge  | 172.xx.xx.xx  | 54.64.xx.xx   | running |
| i-xxxxxxxx | hoge2             | m3.2xlarge | 172.xx.xx.xx  | 54.64.xx.xx   | running |
+------------+-------------------+------------+---------------+---------------+---------+

ステータス確認

# ec2ctl status hoge  --profile=sato --region=ap-northeast-1
Instance found: 
* Name:              hoge
* Status:            running
* Instance Type:     m3.medium
* Private IP:        172.xx.xx.xx
* Public IP:         54.64.xx.xx
* Availability Zone: ap-northeast-1c
* Other Tags:        {"num"=>"2"}

インスタンス起動

# ec2ctl start hoge  --profile=sato --region=ap-northeast-1

インスタンス停止

# ec2ctl stop hoge  --profile=sato --region=ap-northeast-1

SSH オプション

➜  ~  ec2ctl help ssh
Usage:
  ec2ctl ssh NAME COMMAND

Options:
  u, [--user=USER]
                                               # Default: ec2-user
  p, [--port=PORT]
                                               # Default: 22
  i, [--identity-file=IDENTITY_FILE]
                                               # Default: ~/.ssh/id_rsa
  P, [--passphrase=PASSPHRASE]
      [--via-public-ip], [--no-via-public-ip]
  k, [--access-key-id=ACCESS_KEY_ID]
  s, [--secret-access-key=SECRET_ACCESS_KEY]
  r, [--region=REGION]
      [--profile=PROFILE]
      [--color], [--no-color]
                                               # Default: true

元記事はこちらです。
ec2ctlを利用する