2016年11月19日土曜日

aws-cli で EC2 インスタンスを作成する


aws-cli でEC2インスタンスを作ります。

まず、--dry-run を指定して、引数などに間違いがないかチェックしてみます。

[root@centos6 ~]# aws ec2 run-instances --image-id ami-1c221e76 --key-name virginia_key --security-group-ids sg-bbf176df --instance-type t2.micro --placement "AvailabilityZone=us-east-1b,GroupName=,Tenancy=default" --block-device-mappings "DeviceName=/dev/sda1,Ebs={DeleteOnTermination=true,VolumeType=gp2}" --monitoring "Enabled=false" --disable-api-termination --private-ip-address 10.0.11.10 --associate-public-ip-address --subnet-id subnet-f528a2ad --count 1 --output table --dry-run

An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set.


次に --dry-run を外して、実行します。
EC2インスタンスの作成に成功すると、以下のように表示されます。

[root@centos6 ~]# aws ec2 run-instances --image-id ami-1c221e76 --key-name virginia_key --security-group-ids sg-bbf176df --instance-type t2.micro --placement "AvailabilityZone=us-east-1b,GroupName=,Tenancy=default" --block-device-mappings "DeviceName=/dev/sda1,Ebs={DeleteOnTermination=true,VolumeType=gp2}" --monitoring "Enabled=false" --disable-api-termination --private-ip-address 10.0.11.10 --associate-public-ip-address --subnet-id subnet-f528a2ad --count 1 --output table
-----------------------------------------------------------
|                      RunInstances                       |
+----------------------------+----------------------------+
|  OwnerId                   |  544509011205              |
|  ReservationId             |  r-2497ec97                |
+----------------------------+----------------------------+
||                       Instances                       ||
|+------------------------+------------------------------+|
||  AmiLaunchIndex        |  0                           ||
||  Architecture          |  x86_64                      ||
||  ClientToken           |                              ||
||  EbsOptimized          |  False                       ||
||  Hypervisor            |  xen                         ||
||  ImageId               |  ami-1c221e76                ||
||  InstanceId            |  i-bca3812f                  ||
||  InstanceType          |  t2.micro                    ||
||  KeyName               |  virginia_key                ||
||  LaunchTime            |  2016-11-19T06:41:57.000Z    ||
||  PrivateDnsName        |  ip-10-0-11-10.ec2.internal  ||
||  PrivateIpAddress      |  10.0.11.10                  ||
||  PublicDnsName         |                              ||
||  RootDeviceName        |  /dev/sda1                   ||
||  RootDeviceType        |  ebs                         ||
||  SourceDestCheck       |  True                        ||
||  StateTransitionReason |                              ||
||  SubnetId              |  subnet-f528a2ad             ||
||  VirtualizationType    |  hvm                         ||
||  VpcId                 |  vpc-d480c3b1                ||
|+------------------------+------------------------------+|
|||                     Monitoring                      |||
||+----------------------+------------------------------+||
|||  State               |  disabled                    |||
||+----------------------+------------------------------+||
|||                  NetworkInterfaces                  |||
||+---------------------+-------------------------------+||
|||  Description        |                               |||
|||  MacAddress         |  0e:99:1e:0e:11:6a            |||
|||  NetworkInterfaceId |  eni-f27d1233                 |||
|||  OwnerId            |  544509011205                 |||
|||  PrivateDnsName     |  ip-10-0-11-10.ec2.internal   |||
|||  PrivateIpAddress   |  10.0.11.10                   |||
|||  SourceDestCheck    |  True                         |||
|||  Status             |  in-use                       |||
|||  SubnetId           |  subnet-f528a2ad              |||
|||  VpcId              |  vpc-d480c3b1                 |||
||+---------------------+-------------------------------+||
||||                    Attachment                     ||||
|||+----------------------+----------------------------+|||
||||  AttachTime          |  2016-11-19T06:41:57.000Z  ||||
||||  AttachmentId        |  eni-attach-ab648822       ||||
||||  DeleteOnTermination |  True                      ||||
||||  DeviceIndex         |  0                         ||||
||||  Status              |  attaching                 ||||
|||+----------------------+----------------------------+|||
||||                      Groups                       ||||
|||+-----------------------+---------------------------+|||
||||  GroupId              |  sg-bbf176df              ||||
||||  GroupName            |  default                  ||||
|||+-----------------------+---------------------------+|||
||||                PrivateIpAddresses                 ||||
|||+-------------------+-------------------------------+|||
||||  Primary          |  True                         ||||
||||  PrivateDnsName   |  ip-10-0-11-10.ec2.internal   ||||
||||  PrivateIpAddress |  10.0.11.10                   ||||
|||+-------------------+-------------------------------+|||
|||                      Placement                      |||
||+------------------------------+----------------------+||
|||  AvailabilityZone            |  us-east-1b          |||
|||  GroupName                   |                      |||
|||  Tenancy                     |  default             |||
||+------------------------------+----------------------+||
|||                   SecurityGroups                    |||
||+------------------------+----------------------------+||
|||  GroupId               |  sg-bbf176df               |||
|||  GroupName             |  default                   |||
||+------------------------+----------------------------+||
|||                        State                        |||
||+---------------------+-------------------------------+||
|||  Code               |  0                            |||
|||  Name               |  pending                      |||
||+---------------------+-------------------------------+||
|||                     StateReason                     |||
||+-------------------------+---------------------------+||
|||  Code                   |  pending                  |||
|||  Message                |  pending                  |||
||+-------------------------+---------------------------+||