AWS

AWS便利ナレッジ集

More than 1 year has passed since last update.


AWS便利ナレッジ


1.EC2インスタンス作成


EC2インスタンス作成用JSONファイル作成

aws ec2 run-instances --generate-cli-skeleton > run-instances-test.json



EC2インスタンス作成用JSONファイル作成

aws ec2 run-instances --cli-input-json file://run-instances-test.json


次の構成でインスタンスを作成してみます。

* Amazon Linux

* t2.micro

* key-name の指定

* 既存のsecurity-groupの指定

* subnet-id の指定

* secondary-private-ip-addressesの指定

* associate-public-ip-address

* 20GBのEBSの割当

[実行結果]


EC2インスタンス作成用JSONファイル作成

$ aws ec2 run-instances --image-id ami-xxxxxxxx --instance-type t2.micro --key-name test-xxxxxxxx --subnet-id subnet-xxxxxxxx --security-group-ids sg-xxxxxxaa sg-xxxxxxbb --secondary-private-ip-addresses 192.168.1.99 

--associate-public-ip-address --block-device-mappings "[{\"DeviceName\": \"/dev/xvda\",\"Ebs\":{\"Vo
lumeSize
\":20}}]"
{
"OwnerId": "xxxxxxxxxxxx",
"ReservationId": "r-xxxxxxxx",
"Groups": [],
"Instances": [
{
"Monitoring": {
"State": "disabled"
},
"PublicDnsName": "",
"RootDeviceType": "ebs",
"State": {
"Code": 0,
"Name": "pending"
},
"EbsOptimized": false,
"LaunchTime": "2015-08-18T01:36:45.000Z",
"PrivateIpAddress": "192.168.1.178",
"ProductCodes": [],
"VpcId": "vpc-xxxxxxxx",
"StateTransitionReason": "",
"InstanceId": "i-xxxxxxxx",
"ImageId": "ami-cbf90ecb",
"PrivateDnsName": "ip-192-168-1-178.ap-northeast-1.compute.internal",
"KeyName": "test-xxxxxxxx",
"SecurityGroups": [
{
"GroupName": "https only",
"GroupId": "sg-xxxxxxaa"
},
{
"GroupName": "ssh-only",
"GroupId": "sg-xxxxxxbb"
}
],
"ClientToken": "",
"SubnetId": "subnet-xxxxxxxx",
"InstanceType": "t2.micro",
"NetworkInterfaces": [
{
"Status": "in-use",
"MacAddress": "06:60:51:02:cd:d1",
"SourceDestCheck": true,
"VpcId": "vpc-xxxxxxxx",
"Description": "",
"NetworkInterfaceId": "eni-xxxxxxxx",
"PrivateIpAddresses": [
{
"Primary": true,
"PrivateIpAddress": "192.168.1.178"
},
{
"PrivateDnsName": "",
"Primary": false,
"PrivateIpAddress": "192.168.1.99"
}
],
"Attachment": {
"Status": "attaching",
"DeviceIndex": 0,
"DeleteOnTermination": true,
"AttachmentId": "eni-attach-xxxxxxxx",
"AttachTime": "2015-08-18T01:36:45.000Z"
},
"Groups": [
{
"GroupName": "https only",
"GroupId": "sg-xxxxxxaa"
},
{
"GroupName": "ssh-only",
"GroupId": "sg-xxxxxxxxbb"
}
],
"SubnetId": "subnet-xxxxxxxx",
"OwnerId": "xxxxxxxxxxxx",
"PrivateIpAddress": "192.168.1.178"
}
],
"SourceDestCheck": true,
"Placement": {
"Tenancy": "default",
"GroupName": "",
"AvailabilityZone": "ap-northeast-1a"
},
"Hypervisor": "xen",
"BlockDeviceMappings": [],
"Architecture": "x86_64",
"StateReason": {
"Message": "pending",
"Code": "pending"
},
"RootDeviceName": "/dev/xvda",
"VirtualizationType": "hvm",
"AmiLaunchIndex": 0
}
]
}