|« PreviousNext »|
|Did this page help you? Yes | No | Tell us about it...|
Before running an Amazon EC2 instance, ensure that you have created a security group and a key pair for your instance. For information about creating a key pair, see Create a Key Pair. For information about creating a security group, see Create an Amazon EC2 Security Group.
To run an Amazon EC2 instance
Create and initialize a RunInstancesRequest instance. Specify the Amazon Machine Image (AMI) (withImageId), the instance type (withInstanceType), the minimum (withMinCount) and maximum (withMaxCount) number of instances to run, key pair name (withKeyName), and the name of one or more security groups (withSecurityGroups), as follows:
RunInstancesRequest runInstancesRequest = 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
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.
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.