[AWS]ec2-ami-toolsとec2-api-toolsをmacにインストールする | iii threetreeslight

October 19, 2012

[AWS]ec2-ami-toolsとec2-api-toolsをmacにインストールする

現在、AWSを利用してサービスをくみ上げているのですが、レイテンシーを少しでも軽減するために各リージョンにサーバーを用意しようと思います。

上記に伴い、別リージョンに同じサーバーを立てるため、ami-toolsとapi-toolsをインストールしました。其の手順をメモ。


AWSのサイトから証明書と鍵を入手します。


鍵の配置と権限変更

$ mkidr ~/.ec2
$ mv pk-.pem cert-.pem ~/.ec2
$ chmod 600 ~/.ec2/*.pem


ec2-ami-toolsとec2-api-toolsをhomebrewでインストール

$ brew search ec2
ec2-ami-tools  ec2-api-tools

$ brew install ec2-api-tools
Software installed with other package managers causes known problems for
Homebrew. If a formula fails to build, uninstall MacPorts/Fink and try again.
==> Downloading http://ec2-downloads.s3.amazonaws.com/ec2-api-tools-1.5.2.5.zip
######################################################################## 100.0%
==> Caveats
Before you can use these tools you must export some variables to your $SHELL
and download your X.509 certificate and private key from Amazon Web Services.

Your certificate and private key are available at:
http://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key

Download two “.pem” files, one starting with pk-, and one starting with cert-.
You need to put both into a folder in your home directory, ~/.ec2.

To export the needed variables, add them to your dotfiles.
 * On Bash, add them to ~/.bash_profile.
 * On Zsh, add them to ~/.zprofile instead.

export JAVA_HOME=“$(/usr/libexec/java_home)”
export EC2_PRIVATE_KEY=“$(/bin/ls $HOME/.ec2/pk-.pem)”
export EC2_CERT=“$(/bin/ls $HOME/.ec2/cert-.pem)”
export EC2_HOME=“/usr/local/Cellar/ec2-api-tools/1.5.2.5/jars”
==> Summary
/usr/local/Cellar/ec2-api-tools/1.5.2.5: 322 files, 15M, built in 45 seconds

$ brew install ec2-ami-tools
Software installed with other package managers causes known problems for
Homebrew. If a formula fails to build, uninstall MacPorts/Fink and try again.
==> Downloading http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools-1.3-45758.zip
######################################################################## 100.0%
==> Caveats
Before you can use these tools you must export some variables to your $SHELL
and download your X.509 certificate and private key from Amazon Web Services.

Your certificate and private key are available at:
http://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key

Download two “.pem” files, one starting with pk-, and one starting with cert-.
You need to put both into a folder in your home directory, ~/.ec2.

To export the needed variables, add them to your dotfiles.
 * On Bash, add them to ~/.bash_profile.
 * On Zsh, add them to ~/.zprofile instead.

export JAVA_HOME=“$(/usr/libexec/java_home)”
export EC2_PRIVATE_KEY=“$(/bin/ls $HOME/.ec2/pk-.pem)”
export EC2_CERT=“$(/bin/ls $HOME/.ec2/cert-.pem)”
export EC2_AMITOOL_HOME=“/usr/local/Cellar/ec2-ami-tools/1.3-45758/jars”
==> Summary
/usr/local/Cellar/ec2-ami-tools/1.3-45758: 87 files, 532K, built in 3 seconds


環境変数を設定

$ vim ~/.bashrc
export JAVA_HOME=“$(/usr/libexec/java_home)”
export EC2_PRIVATE_KEY=“$(/bin/ls $HOME/.ec2/pk-.pem)”
export EC2_CERT=“$(/bin/ls $HOME/.ec2/cert-.pem)”
export EC2_HOME=“/usr/local/Cellar/ec2-api-tools/1.5.2.5/jars”
export EC2_AMITOOL_HOME=“/usr/local/Cellar/ec2-ami-tools/1.3-45758/jars”
export EC2_URL=“http://ec2.us-west-1.amazonaws.com"

$ source ~/.bashrc


動作テスト

$ ec2ver
1.5.2.5 2012-03-01

$ ec2-describe-regions
REGION  eu-west-1       ec2.eu-west-1.amazonaws.com
REGION  sa-east-1       ec2.sa-east-1.amazonaws.com
REGION  us-east-1       ec2.us-east-1.amazonaws.com
REGION  ap-northeast-1  ec2.ap-northeast-1.amazonaws.com
REGION  us-west-2       ec2.us-west-2.amazonaws.com
REGION  us-west-1       ec2.us-west-1.amazonaws.com
REGION  ap-southeast-1  ec2.ap-southeast-1.amazonaws.com

$ ec2-describe-instances
-> EC2_URLで指定されたリージョンで利用しているインスタンスが表示されます。