プログラマでありたい

おっさんになっても、プログラマでありつづけたい

Amazon EC2のインスタンスの起動でよく使うオプション

 Amazon EC2のインスタンスの方法は、基本的に下記のとおりです。


ec2-run-instances AMI-ID -k ログインキー


 起動オプションはたくさんあるのですが、その中でよく使うオプションを紹介します。

-g, --group GROUP [--group GROUP...]

セキュリティグループの指定するオプションです。指定しない場合はdefaultグループになります。例えば、Webサーバのグループ、DBサーバのグループといったような使い方が出来ます。詳細はまた別で書きます。

-z, --availability-zone ZONE

インスタンスを稼働させる物理ロケーションを指定します。ec2からEBSをマウントする場合は、同一ロケーションである必要があります。また、指定しない場合はランダムで決まるっぽい(?)ので、気がつかないうちにディザスタリカバリをしていたという何とも言い難い事態になります。使用可能なゾーンを調べるのは、ec2-describe-availability-zonesで可能です。ちなみにゾーンの上の概念にリージョンというのがあります。これは、米国東部とかEU西部とかいったレベルです。もうすぐアジアが追加される予定です。


 主にはこの二つだけですね。後は、インスタンスのサイズを変えるとかもありますが、あまり利用していないです。
以下、ヘルプの内容です。

$ ec2-run-instances --help
SYNOPSIS
ec2run (ec2-run-instances)
ec2run [GENERAL OPTIONS] AMI [SPECIFIC OPTIONS]
GENERAL NOTES
Any command option/parameter may be passed a value of '-' to indicate
that values for that option should be read from stdin.
DESCRIPTION
Launch a number of instances of a specified AMI.
The AMI parameter is the AMI ID of the AMI to launch.

GENERAL OPTIONS

-K, --private-key KEY
Specify KEY as the private key to use. Defaults to the value of the
EC2_PRIVATE_KEY environment variable (if set). Overrides the default.

-C, --cert CERT
Specify CERT as the X509 certificate to use. Defaults to the value
of the EC2_CERT environment variable (if set). Overrides the default.

-U, --url URL
Specify URL as the web service URL to use. Defaults to the value of
'https://ec2.amazonaws.com' or to that of the EC2_URL environment
variable (if set). Overrides the default.

--region REGION
Specify REGION as the web service region to use.
This option will override the URL specified by the "-U URL" option and EC2_URL environment variable.

-v, --verbose
Verbose output.

-?, --help
Display this help.

-H, --headers
Display column headers.

--debug
Display additional debugging information.

--show-empty-fields
Indicate empty fields.

--connection-timeout TIMEOUT
Specify a connection timeout TIMEOUT (in seconds).

--request-timeout TIMEOUT
Specify a request timeout TIMEOUT (in seconds).

SPECIFIC OPTIONS

-B, --block-device-mapping MAPPING
Specifies one or more block-device-mappings to launch instances with.
Please see latest Developer's Guide for acceptable mappings.

-n, --instance-count MIN[-MAX]
The number of instances to attempt to launch. May be specified as a
single integer or as a range (min-max). This specifies the minumum
and maximum number of instances to attempt to launch. If a single
integer is specified min and max are both set to that value.

-g, --group GROUP [--group GROUP...]
Specifies the security group (or groups if specified multiple times)
within which the instance(s) should be run. Determines the ingress
firewall rules that will be applied to the launched instances.
Defaults to the user's default group if not supplied.

-k, --key KEY-PAIR
Specifies the key pair to use when launching this instance.

-d, --user-data DATA
Specifies the user data to be made available to the instances in this
reservation.

-f, --user-data-file DATA-FILE
Specifies the file containing user data to be made available to the
instances in this reservation.

--addressing ADDRESSING
Specifies the addressing type to use for the instances. Refer to the
latest Developer's Guide for valid values.

-t, --instance-type TYPE
Specifies the type of instance to be launched. Refer to the latest
Developer's Guide for valid values.

-z, --availability-zone ZONE
Specifies the availability zone to launch the instances in. Run the
'ec2-describe-availability-zones' command for a list of values, and
see the latest Developer's Guide for their meanings.

--kernel KERNEL-ID
Specifies the kernel-ID of the kernel to launch instances with.

--ramdisk RAMDISK-ID
Specifies the ramdisk-ID of the ramdisk to launch instances with.


Amazon EC2/S3の使い方目次