User guide

secretKey=YOUR_SECRET_KEY
accessKey=YOUR_ACCESS_KEY
Specify your AWS credentials as values for the secretKey and accessKey entries.To learn more about
your AWS credentials, including where to find them, go to AWS Security Credentials.
After you create this file, you are ready to create and initialize your Amazon EC2 client.
To create and initialize an Amazon EC2 client
1. Create and initialize an AWSCredentials instance. Specify the AwsCredentials.properties
file you created, as follows:
AWSCredentials credentials =
new PropertiesCredentials(
AwsConsoleApp.class.getResourceAsStream("AwsCredentials.proper
ties"));
2. Use the AWSCredentials object to create a new AmazonEC2Client instance, as follows:
amazonEC2Client =
new AmazonEC2Client(credentials);
3. By default, the service endpoint is ec2.us-east-1.amazonaws.com.To specify a different endpoint,
use the setEndpoint method. For example:
amazonEC2Client.setEndpoint("ec2.us-west-2.amazonaws.com");
The AWS SDK for Java uses US East (N.Virginia) as the default region if you do not specify a region
in your code. However, the AWS Management Console uses US West (Oregon) as its default.
Therefore, when using the AWS Management Console in conjunction with your development, be
sure to specify the same region in both your code and the console.
Go to Regions and Endpoints for the current list of regions and corresponding endpoints for all AWS
services.
Before running an Amazon EC2 instance, you will need to create an Amazon EC2 security group, authorize
security group ingress, and create a key pair to allow you to log into your instance.
For information about creating a security group, see Create an Amazon EC2 Security Group (p. 24).
For information about authorizing security group ingress, see Authorize Amazon EC2 Security Group
Ingress (p. 25).
For information about creating a key pair, see Create a Key Pair (p. 26).
For information about running your Amazon EC2 instance, see Run an Amazon EC2 Instance (p. 27).
Create an Amazon EC2 Security Group
An Amazon EC2 security group controls traffic through your Amazon EC2 instances, much like a firewall.
If you do not create a security group, Amazon EC2 provides a default security group that allows no inbound
traffic. For more information about security groups, go to Security Group Concepts.
Version v1.0.0
24
AWS SDK for Java Developer Guide
Starting an Amazon EC2 Instance