Submit
Path:
~
/
/
lib
/
python2.7
/
site-packages
/
awscli
/
examples
/
ec2
/
File Content:
run-instances.rst
**To launch an instance in EC2-Classic** This example launches a single instance of type ``c3.large``. The key pair and security group, named ``MyKeyPair`` and ``MySecurityGroup``, must exist. Command:: aws ec2 run-instances --image-id ami-1a2b3c4d --count 1 --instance-type c3.large --key-name MyKeyPair --security-groups MySecurityGroup Output:: { "OwnerId": "123456789012", "ReservationId": "r-08626e73c547023b1", "Groups": [ { "GroupName": "MySecurityGroup", "GroupId": "sg-903004f8" } ], "Instances": [ { "Monitoring": { "State": "disabled" }, "PublicDnsName": null, "RootDeviceType": "ebs", "State": { "Code": 0, "Name": "pending" }, "EbsOptimized": false, "LaunchTime": "2013-07-19T02:42:39.000Z", "ProductCodes": [], "StateTransitionReason": null, "InstanceId": "i-1234567890abcdef0", "ImageId": "ami-1a2b3c4d", "PrivateDnsName": null, "KeyName": "MyKeyPair", "SecurityGroups": [ { "GroupName": "MySecurityGroup", "GroupId": "sg-903004f8" } ], "ClientToken": null, "InstanceType": "c3.large", "NetworkInterfaces": [], "Placement": { "Tenancy": "default", "GroupName": null, "AvailabilityZone": "us-east-1b" }, "Hypervisor": "xen", "BlockDeviceMappings": [], "Architecture": "x86_64", "StateReason": { "Message": "pending", "Code": "pending" }, "RootDeviceName": "/dev/sda1", "VirtualizationType": "hvm", "AmiLaunchIndex": 0 } ] } **To launch an instance in EC2-VPC** This example launches a single instance of type ``t2.micro`` into the specified subnet. The key pair named ``MyKeyPair`` and the security group sg-903004f8 must exist. Command:: aws ec2 run-instances --image-id ami-abc12345 --count 1 --instance-type t2.micro --key-name MyKeyPair --security-group-ids sg-903004f8 --subnet-id subnet-6e7f829e Output:: { "OwnerId": "123456789012", "ReservationId": "r-08626e73c547023b2", "Groups": [], "Instances": [ { "Monitoring": { "State": "disabled" }, "PublicDnsName": null, "RootDeviceType": "ebs", "State": { "Code": 0, "Name": "pending" }, "EbsOptimized": false, "LaunchTime": "2013-07-19T02:42:39.000Z", "PrivateIpAddress": "10.0.1.114", "ProductCodes": [], "VpcId": "vpc-1a2b3c4d", "InstanceId": "i-1234567890abcdef5", "ImageId": "ami-abc12345", "PrivateDnsName": "ip-10-0-1-114.ec2.internal", "KeyName": "MyKeyPair", "SecurityGroups": [ { "GroupName": "MySecurityGroup", "GroupId": "sg-903004f8" } ], "ClientToken": null, "SubnetId": "subnet-6e7f829e", "InstanceType": "t2.micro", "NetworkInterfaces": [ { "Status": "in-use", "MacAddress": "0e:ad:05:3b:60:52", "SourceDestCheck": true, "VpcId": "vpc-1a2b3c4d", "Description": "null", "NetworkInterfaceId": "eni-a7edb1c9", "PrivateIpAddresses": [ { "PrivateDnsName": "ip-10-0-1-114.ec2.internal", "Primary": true, "PrivateIpAddress": "10.0.1.114" } ], "Ipv6Addresses": [], "PrivateDnsName": "ip-10-0-1-114.ec2.internal", "Attachment": { "Status": "attached", "DeviceIndex": 0, "DeleteOnTermination": true, "AttachmentId": "eni-attach-52193138", "AttachTime": "2013-07-19T02:42:39.000Z" }, "Groups": [ { "GroupName": "MySecurityGroup", "GroupId": "sg-903004f8" } ], "SubnetId": "subnet-6e7f829e", "OwnerId": "123456789012", "PrivateIpAddress": "10.0.1.114" } ], "SourceDestCheck": true, "Placement": { "Tenancy": "default", "GroupName": null, "AvailabilityZone": "us-east-1b" }, "Hypervisor": "xen", "BlockDeviceMappings": [], "Architecture": "x86_64", "StateReason": { "Message": "pending", "Code": "pending" }, "RootDeviceName": "/dev/sda1", "VirtualizationType": "hvm", "AmiLaunchIndex": 0 } ] } The following example requests a public IP address for an instance that you're launching into a nondefault subnet: Command:: aws ec2 run-instances --image-id ami-c3b8d6aa --count 1 --instance-type t2.medium --key-name MyKeyPair --security-group-ids sg-903004f8 --subnet-id subnet-6e7f829e --associate-public-ip-address **To launch an instance using a block device mapping** Add the following parameter to your ``run-instances`` command to specify block devices:: --block-device-mappings file://mapping.json To add an Amazon EBS volume with the device name ``/dev/sdh`` and a volume size of 100, specify the following in mapping.json:: [ { "DeviceName": "/dev/sdh", "Ebs": { "VolumeSize": 100 } } ] To add ``ephemeral1`` as an instance store volume with the device name ``/dev/sdc``, specify the following in mapping.json:: [ { "DeviceName": "/dev/sdc", "VirtualName": "ephemeral1" } ] To omit a device specified by the AMI used to launch the instance (for example, ``/dev/sdf``), specify the following in mapping.json:: [ { "DeviceName": "/dev/sdf", "NoDevice": "" } ] You can view only the Amazon EBS volumes in your block device mapping using the console or the ``describe-instances`` command. To view all volumes, including the instance store volumes, use the following command. Command:: curl http://169.254.169.254/latest/meta-data/block-device-mapping/ Output:: ami ephemeral1 Note that ``ami`` represents the root volume. To get details about the instance store volume ``ephemeral1``, use the following command. Command:: curl http://169.254.169.254/latest/meta-data/block-device-mapping/ephemeral1 Output:: sdc **To launch an instance with a modified block device mapping** You can change individual characteristics of existing AMI block device mappings to suit your needs. Perhaps you want to use an existing AMI, but you want a larger root volume than the usual 8 GiB. Or, you would like to use a General Purpose (SSD) volume for an AMI that currently uses a Magnetic volume. Use the ``describe-images`` command with the image ID of the AMI you want to use to find its existing block device mapping. You should see a block device mapping in the output:: { "DeviceName": "/dev/sda1", "Ebs": { "DeleteOnTermination": true, "SnapshotId": "snap-1234567890abcdef0", "VolumeSize": 8, "VolumeType": "standard", "Encrypted": false } } You can modify the above mapping by changing the individual parameters. For example, to launch an instance with a modified block device mapping, add the following parameter to your ``run-instances`` command to change the above mapping's volume size and type:: --block-device-mappings file://mapping.json Where mapping.json contains the following:: [ { "DeviceName": "/dev/sda1", "Ebs": { "DeleteOnTermination": true, "SnapshotId": "snap-1234567890abcdef0", "VolumeSize": 100, "VolumeType": "gp2" } } ] **To launch an instance with user data** You can launch an instance and specify user data that performs instance configuration, or that runs a script. The user data needs to be passed as normal string, base64 encoding is handled internally. The following example passes user data in a file called ``my_script.txt`` that contains a configuration script for your instance. The script runs at launch. Command:: aws ec2 run-instances --image-id ami-abc1234 --count 1 --instance-type m4.large --key-name keypair --user-data file://my_script.txt --subnet-id subnet-abcd1234 --security-group-ids sg-abcd1234 For more information about launching instances, see `Using Amazon EC2 Instances`_ in the *AWS Command Line Interface User Guide*. .. _`Using Amazon EC2 Instances`: http://docs.aws.amazon.com/cli/latest/userguide/cli-ec2-launch.html **To launch an instance with an instance profile** This example shows the use of the ``iam-instance-profile`` option to specify an `IAM instance profile`_ by name. .. _`IAM instance profile`: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html Command:: aws ec2 run-instances --iam-instance-profile Name=MyInstanceProfile --image-id ami-1a2b3c4d --count 1 --instance-type t2.micro --key-name MyKeyPair --security-groups MySecurityGroup
Submit
FILE
FOLDER
Name
Size
Permission
Action
accept-vpc-peering-connection.rst
691 bytes
0644
allocate-address.rst
560 bytes
0644
allocate-hosts.rst
379 bytes
0644
assign-ipv6-addresses.rst
1102 bytes
0644
assign-private-ip-addresses.rst
866 bytes
0644
associate-address.rst
1014 bytes
0644
associate-dhcp-options.rst
557 bytes
0644
associate-iam-instance-profile.rst
650 bytes
0644
associate-route-table.rst
286 bytes
0644
associate-subnet-cidr-block.rst
521 bytes
0644
associate-vpc-cidr-block.rst
424 bytes
0644
attach-classic-link-vpc.rst
328 bytes
0644
attach-internet-gateway.rst
272 bytes
0644
attach-network-interface.rst
327 bytes
0644
attach-volume.rst
498 bytes
0644
attach-vpn-gateway.rst
346 bytes
0644
authorize-security-group-egress.rst
746 bytes
0644
authorize-security-group-ingress.rst
3199 bytes
0644
bundle-instance.rst
914 bytes
0644
cancel-bundle-task.rst
514 bytes
0644
cancel-conversion-task.rst
274 bytes
0644
cancel-export-task.rst
240 bytes
0644
cancel-spot-fleet-requests.rst
1140 bytes
0644
cancel-spot-instance-requests.rst
368 bytes
0644
confirm-product-instance.rst
292 bytes
0644
copy-image.rst
323 bytes
0644
copy-snapshot.rst
462 bytes
0644
create-customer-gateway.rst
455 bytes
0644
create-dhcp-options.rst
527 bytes
0644
create-egress-only-internet-gateway.rst
469 bytes
0644
create-flow-logs.rst
662 bytes
0644
create-image.rst
1318 bytes
0644
create-instance-export-task.rst
921 bytes
0644
create-internet-gateway.rst
274 bytes
0644
create-key-pair.rst
435 bytes
0644
create-nat-gateway.rst
645 bytes
0644
create-network-acl-entry.rst
778 bytes
0644
create-network-acl.rst
844 bytes
0644
create-network-interface.rst
1138 bytes
0644
create-placement-group.rst
193 bytes
0644
create-route-table.rst
561 bytes
0644
create-route.rst
1142 bytes
0644
create-security-group.rst
775 bytes
0644
create-snapshot.rst
617 bytes
0644
create-spot-datafeed-subscription.rst
413 bytes
0644
create-subnet.rst
1781 bytes
0644
create-tags.rst
1708 bytes
0644
create-volume.rst
1265 bytes
0644
create-vpc-endpoint.rst
777 bytes
0644
create-vpc-peering-connection.rst
1252 bytes
0644
create-vpc.rst
1817 bytes
0644
create-vpn-connection-route.rst
290 bytes
0644
create-vpn-connection.rst
1548 bytes
0644
create-vpn-gateway.rst
327 bytes
0644
delete-customer-gateway.rst
216 bytes
0644
delete-dhcp-options.rst
209 bytes
0644
delete-egress-only-internet-gateway.rst
268 bytes
0644
delete-flow-logs.rst
179 bytes
0644
delete-internet-gateway.rst
217 bytes
0644
delete-key-pair.rst
377 bytes
0644
delete-nat-gateway.rst
231 bytes
0644
delete-network-acl-entry.rst
265 bytes
0644
delete-network-acl.rst
196 bytes
0644
delete-network-interface.rst
220 bytes
0644
delete-placement-group.rst
162 bytes
0644
delete-route-table.rst
196 bytes
0644
delete-route.rst
244 bytes
0644
delete-security-group.rst
723 bytes
0644
delete-snapshot.rst
241 bytes
0644
delete-spot-datafeed-subscription.rst
234 bytes
0644
delete-subnet.rst
179 bytes
0644
delete-tags.rst
1226 bytes
0644
delete-volume.rst
240 bytes
0644
delete-vpc-endpoints.rst
373 bytes
0644
delete-vpc-peering-connection.rst
232 bytes
0644
delete-vpc.rst
164 bytes
0644
delete-vpn-connection-route.rst
304 bytes
0644
delete-vpn-connection.rst
208 bytes
0644
delete-vpn-gateway.rst
220 bytes
0644
deregister-image.rst
181 bytes
0644
describe-account-attributes.rst
2187 bytes
0644
describe-addresses.rst
3183 bytes
0644
describe-availability-zones.rst
802 bytes
0644
describe-bundle-tasks.rst
564 bytes
0644
describe-classic-link-instances.rst
1248 bytes
0644
describe-conversion-tasks.rst
1394 bytes
0644
describe-customer-gateways.rst
1090 bytes
0644
describe-dhcp-options.rst
856 bytes
0644
describe-egress-only-internet-gateways.rst
487 bytes
0644
describe-export-tasks.rst
807 bytes
0644
describe-flow-logs.rst
704 bytes
0644
describe-hosts.rst
1445 bytes
0644
describe-iam-instance-profile-associations.rst
934 bytes
0644
describe-id-format.rst
1139 bytes
0644
describe-identity-id-format.rst
1098 bytes
0644
describe-image-attribute.rst
699 bytes
0644
describe-images.rst
1920 bytes
0644
describe-instance-attribute.rst
1695 bytes
0644
describe-instance-status.rst
1042 bytes
0644
describe-instances.rst
1334 bytes
0644
describe-internet-gateways.rst
1171 bytes
0644
describe-key-pairs.rst
557 bytes
0644
describe-moving-addresses.rst
469 bytes
0644
describe-nat-gateways.rst
1160 bytes
0644
describe-network-acls.rst
5592 bytes
0644
describe-network-interface-attribute.rst
1926 bytes
0644
describe-network-interfaces.rst
5295 bytes
0644
describe-placement-groups.rst
354 bytes
0644
describe-prefix-lists.rst
350 bytes
0644
describe-regions.rst
2687 bytes
0644
describe-reserved-instances-modifications.rst
1658 bytes
0644
describe-reserved-instances-offerings.rst
3560 bytes
0644
describe-reserved-instances.rst
2320 bytes
0644
describe-route-tables.rst
3349 bytes
0644
describe-scheduled-instance-availability.rst
1422 bytes
0644
describe-scheduled-instances.rst
1282 bytes
0644
describe-security-group-references.rst
543 bytes
0644
describe-security-groups.rst
4811 bytes
0644
describe-snapshot-attribute.rst
401 bytes
0644
describe-snapshots.rst
1850 bytes
0644
describe-spot-datafeed-subscription.rst
385 bytes
0644
describe-spot-fleet-instances.rst
565 bytes
0644
describe-spot-fleet-request-history.rst
1698 bytes
0644
describe-spot-fleet-requests.rst
4931 bytes
0644
describe-spot-instance-requests.rst
2460 bytes
0644
describe-spot-price-history.rst
2121 bytes
0644
describe-stale-security-groups.rst
2018 bytes
0644
describe-subnets.rst
1912 bytes
0644
describe-tags.rst
3753 bytes
0644
describe-volume-attribute.rst
383 bytes
0644
describe-volume-status.rst
1507 bytes
0644
describe-volumes.rst
3303 bytes
0644
describe-vpc-attribute.rst
1045 bytes
0644
describe-vpc-classic-link-dns-support.rst
416 bytes
0644
describe-vpc-classic-link.rst
659 bytes
0644
describe-vpc-endpoint-services.rst
244 bytes
0644
describe-vpc-endpoints.rst
626 bytes
0644
describe-vpc-peering-connections.rst
2852 bytes
0644
describe-vpcs.rst
2038 bytes
0644
describe-vpn-connections.rst
1273 bytes
0644
describe-vpn-gateways.rst
834 bytes
0644
detach-classic-link-vpc.rst
271 bytes
0644
detach-internet-gateway.rst
277 bytes
0644
detach-network-interface.rst
268 bytes
0644
detach-volume.rst
431 bytes
0644
detach-vpn-gateway.rst
280 bytes
0644
disable-vgw-route-propagation.rst
311 bytes
0644
disable-vpc-classic-link-dns-support.rst
236 bytes
0644
disable-vpc-classic-link.rst
195 bytes
0644
disassociate-address.rst
515 bytes
0644
disassociate-iam-instance-profile.rst
614 bytes
0644
disassociate-route-table.rst
245 bytes
0644
disassociate-subnet-cidr-block.rst
539 bytes
0644
disassociate-vpc-cidr-block.rst
518 bytes
0644
enable-vgw-route-propagation.rst
304 bytes
0644
enable-volume-io.rst
206 bytes
0644
enable-vpc-classic-link-dns-support.rst
233 bytes
0644
enable-vpc-classic-link.rst
192 bytes
0644
get-console-output.rst
308 bytes
0644
get-password-data.rst
979 bytes
0644
import-key-pair.rst
1101 bytes
0644
modify-hosts.rst
1445 bytes
0644
modify-id-format.rst
466 bytes
0644
modify-identity-id-format.rst
762 bytes
0644
modify-image-attribute.rst
1108 bytes
0644
modify-instance-attribute.rst
1476 bytes
0644
modify-instance-placement.rst
332 bytes
0644
modify-network-interface-attribute.rst
1181 bytes
0644
modify-reserved-instances.rst
2045 bytes
0644
modify-snapshot-attribute.rst
655 bytes
0644
modify-spot-fleet-request.rst
663 bytes
0644
modify-subnet-attribute.rst
862 bytes
0644
modify-volume-attribute.rst
293 bytes
0644
modify-vpc-attribute.rst
930 bytes
0644
modify-vpc-endpoint.rst
327 bytes
0644
modify-vpc-peering-connection-options.rst
1830 bytes
0644
monitor-instances.rst
403 bytes
0644
move-address-to-vpc.rst
225 bytes
0644
purchase-reserved-instances-offering.rst
426 bytes
0644
purchase-scheduled-instances.rst
1289 bytes
0644
reboot-instances.rst
412 bytes
0644
register-image.rst
999 bytes
0644
reject-vpc-peering-connection.rst
239 bytes
0644
release-address.rst
498 bytes
0644
release-hosts.rst
376 bytes
0644
replace-iam-instance-profile.rst
721 bytes
0644
replace-network-acl-association.rst
349 bytes
0644
replace-network-acl-entry.rst
405 bytes
0644
replace-route-table-association.rst
349 bytes
0644
replace-route.rst
377 bytes
0644
report-instance-status.rst
243 bytes
0644
request-spot-fleet.rst
5123 bytes
0644
request-spot-instances.rst
4991 bytes
0644
reset-image-attribute.rst
319 bytes
0644
reset-instance-attribute.rst
922 bytes
0644
reset-snapshot-attribute.rst
294 bytes
0644
restore-address-to-classic.rst
282 bytes
0644
revoke-security-group-egress.rst
760 bytes
0644
revoke-security-group-ingress.rst
1044 bytes
0644
run-instances.rst
10149 bytes
0644
run-scheduled-instances.rst
1387 bytes
0644
start-instances.rst
776 bytes
0644
stop-instances.rst
775 bytes
0644
terminate-instances.rst
745 bytes
0644
unassign-ipv6-addresses.rst
434 bytes
0644
unassign-private-ip-addresses.rst
336 bytes
0644
unmonitor-instances.rst
409 bytes
0644
N4ST4R_ID | Naxtarrr