User guide

ipPermission.setFromPort(new Integer(22));
ipPermission.setToPort(new Integer(22));
ipPermission.setIpRanges(ipRanges);
ipPermissions.add(ipPermission);
50
try {
// Authorize the ports to the used.
AuthorizeSecurityGroupIngressRequest ingressRequest =
new AuthorizeSecurityGroupIngressRequest("GettingStartedGroup",ip
Permissions);
55 ec2.authorizeSecurityGroupIngress(ingressRequest);
} catch (AmazonServiceException ase) {
// Ignore because this likely means the zone has
// already been authorized.
System.out.println(ase.getMessage());
60 }
You can view this entire code sample in the CreateSecurityGroupApp.java code sample. Note you
only need to run this application once to create a new security group.
You can also create the security group using the AWS Toolkit for Eclipse. Go to the toolkit documentation
for more information.
Step 3: Submitting Your Spot Request
To submit a Spot request, you first need to determine the instance type, Amazon Machine Image (AMI),
and maximum bid price you want to use.You must also include the security group we configured previously,
so that you can log into the instance if desired.
There are several instance types to choose from; go to Amazon EC2 Instance Types for a complete list.
For this tutorial, we will use t1.micro, the cheapest instance type available. Next, we will determine the
type of AMI we would like to use.We'll use ami-8c1fece5, the most up-to-date Amazon Linux AMI available
when we wrote this tutorial. The latest AMI may change over time, but you can always determine the
latest version AMI by following these steps:
1. Log into the AWS Management Console, click the EC2 tab, and, from the EC2 Console Dashboard,
attempt to launch an instance.
2. In the window that displays AMIs, just use the AMI ID as shown in the following screen shot.
Alternatively, you can use the DescribeImages API, but leveraging that command is outside the
scope of this tutorial.
Version v1.0.0
38
AWS SDK for Java Developer Guide
Tutorial: Amazon EC2 Spot Instances