User guide

new RunInstancesRequest();
runInstancesRequest.withImageId("ami-4b814f22")
.withInstanceType("m1.small")
.withMinCount(1)
.withMaxCount(1)
.withKeyName(“YourKeyName”)
.withSecurityGroups("YourSecurityGroupName");
You must specify a public or privately-provided AMI. A large selection of Amazon-provided public
AMIs is available for you to use. For a list of public AMIs provided by Amazon, go to Amazon Machine
Images. Ensure that the specified image ID exists in the region in which your client was created.
The instance type must match the AMI you want to run. For 64-bit architecture, you cannot specify
an instance type of m1.small. For more information on instance types, go to Instance Families and
Types.
You must specify a minimum number and a maximum number of instances to launch. If the specified
number of instances is greater than the number of instances you are authorized to launch, no instances
are launched. The specified number of maximum instances must be no greater than the maximum
number allowed for your account; by default, the maximum number of instances is 20. If there are
fewer instances available than the maximum number specified, the largest possible number of images
are launched.
Ensure that the specified key name and security group exists for the region in which your client was
created.
2. Pass the request object into the runInstances method. The method returns a RunInstancesResult
object, as follows:
RunInstancesResult runInstancesResult =
amazonEC2Client.runInstances(runInstancesRequest);
After you have created your Amazon EC2 instance, you can log onto the AWS Management Console to
check the status of the instance.
Once your Amazon EC2 instance is running, you can remotely connect to it using your key pair. For
information about connecting to your instance, see Connect to Your Amazon EC2 Instance (p. 28).
Connect to Your Amazon EC2 Instance
Before connecting to your Amazon EC2 instance, you must ensure that the instance’s SSH/RDP port is
open to traffic.You must also install an SSH/RDP client on the computer you are accessing your instance
from.You will need your Amazon EC2 instance ID and the private key from the key pair you created. For
information on how to obtain the private key, see Create a Key Pair (p. 26).
If you did not authorize ingress for the security group that your instance belongs to, you will not be able
to connect to your instance. By default, Amazon EC2 instances do not permit inbound traffic. For more
information on authorizing security group ingress, see Authorize Security Group Ingress (p. 25).
For information on how to connect to your Amazon EC2 instance, go to Connecting to Instances in the
Amazon Elastic Compute Cloud User Guide.
Version v1.0.0
28
AWS SDK for Java Developer Guide
Starting an Amazon EC2 Instance