AWS SDK for Java Developer Guide Version v1.0.
AWS SDK for Java Developer Guide AWS SDK for Java: Developer Guide Copyright © 2014 Amazon Web Services, Inc. and/or its affiliates. All rights reserved. The following are trademarks of Amazon Web Services, Inc.: Amazon, Amazon Web Services Design, AWS, Amazon CloudFront, Cloudfront, Amazon DevPay, DynamoDB, ElastiCache, Amazon EC2, Amazon Elastic Compute Cloud, Amazon Glacier, Kindle, Kindle Fire, AWS Marketplace Design, Mechanical Turk, Amazon Redshift, Amazon Route 53, Amazon S3, Amazon VPC.
AWS SDK for Java Developer Guide Table of Contents What is the AWS SDK for Java? ....................................................................................................... 1 About the AWS SDK for Java ................................................................................................... 1 Browse the Source at GitHub .......................................................................................... 1 Developing AWS Applications for Android ..................................
AWS SDK for Java Developer Guide About the AWS SDK for Java What is the AWS SDK for Java? The AWS SDK for Java provides a Java API for AWS infrastructure services. Using the SDK for Java, you can build applications that work with Amazon Simple Storage Service (Amazon S3), Amazon Elastic Compute Cloud (Amazon EC2), Amazon SimpleDB, and more. New AWS services are occasionally added to the AWS SDK for Java.
AWS SDK for Java Developer Guide Developing AWS Applications for Android Developing AWS Applications for Android If you are an Android developer, Amazon Web Services publishes a separate SDK specifically for Android development. For more information, go to the documentation for the AWS SDK for Android.
AWS SDK for Java Developer Guide About Amazon Web Services About Amazon Web Services Amazon Web Services (AWS) is a collection of digital infrastructure services that developers can leverage when developing their applications. The services include computing, storage, database, and application synchronization (messaging and queuing). AWS uses a pay-as-you-go service model. You are charged only for the services that you—or your applications—use.
AWS SDK for Java Developer Guide Get an AWS Account and Your AWS Credentials Getting Started This section provides information about how to install, set up and use the SDK for Java. If you have never used the SDK for Java before, you should start here. Topics • Get an AWS Account and Your AWS Credentials (p. 4) • Install a Java Development Environment (p. 5) • Install the AWS SDK for Java (p. 5) • Set up your AWS Credentials for Use with the SDK for Java (p. 6) • Explore the SDK for Java Code Samples (p.
AWS SDK for Java Developer Guide Install a Java Development Environment Note To create access keys, you must have permissions to perform the required IAM actions. For more information, see Granting IAM User Permission to Manage Password Policy and Credentials in Using IAM. 1. Go to the IAM console. 2. 3. 4. From the navigation menu, click Users. Select your IAM user name. Click User Actions, and then click Manage Access Keys. 5. Click Create Access Key.
AWS SDK for Java Developer Guide Set up your AWS Credentials for Use with the SDK for Java If you intend to use the SDK for Java with the Eclipse IDE, you should install the AWS Toolkit for Eclipse, which automatically includes the AWS SDK for Java. For information about how to obtain, install and set up the Toolkit for Eclipse, see Setting Up the AWS Toolkit for Eclipse in the AWS Toolkit for Eclipse Getting Started Guide.
AWS SDK for Java Developer Guide Explore the SDK for Java Code Samples Note You can override the default location of the AWS credential file by setting the AWS_CREDENTIAL_FILE environment variable. For more information, see Providing Credentials (p. 8). Explore the SDK for Java Code Samples The SDK for Java is packaged with a number of code samples, which you can browse on your machine or view on GitHub. For more information about the samples that are provided, see SDK for Java Code Samples (p. 66).
AWS SDK for Java Developer Guide Providing Credentials AWS SDK for Java Basics This section provides important general information about programming with the AWS SDK for Java. Information in this section applies to all services that you might be using with the SDK for Java. For information that is specific to a particular service (EC2, SWF, etc.), see the Using AWS Services (p. 20) section. Topics • Providing AWS Credentials in the AWS SDK for Java (p. 8) • AWS Region Selection (p.
AWS SDK for Java Developer Guide Using the Default Credential Provider Chain Using the Default Credential Provider Chain When you initialize a new service client without supplying any arguments, the SDK for Java will attempt to find AWS credentials using the default credential provider chain implemented by the DefaultAWSCredentialsProviderChain class. The default credential provider chain looks for credentials in this order: 1. Environment Variables – AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
AWS SDK for Java Developer Guide Specifying a Credential Provider or Provider Chain Loading Credentials Once credentials have been set, you can load them using the SDK for Java default credential provider chain. To load credentials using the default credential provider chain • Instantiate an AWS Service client using the default constructor. For example: AmazonS3 s3Client = new AmazonS3Client(); • Alternately, you can specify a new DefaultAWSCredentialsProviderChain in the client's constructor.
AWS SDK for Java Developer Guide See Also To explicitly supply credentials to an AWS client: Instantiate a class that provides the AWSCredentials interface, such as BasicAWSCredentials, supplying it with the AWS access key and secret key you will use for the connection. Provide the class instance to a service client constructor that takes an AWSCredentials interface as input.
AWS SDK for Java Developer Guide Client Networking Configuration The AWS SDK for Java uses the US East (Northern Virginia) Region as the default region if you do not specify a region in your code. However, the AWS Management Console uses US West (Oregon) Region 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.
AWS SDK for Java Developer Guide Setting the JVM TTL for DNS Name Lookups Many resources available to help with configuring TCP buffer sizes and operating system specific TCP settings, including: • TCP Tuning and Network Troubleshooting • Host Tuning Setting the JVM TTL for DNS Name Lookups For Java applications that access Amazon Web Services (AWS), we recommend that you configure your Java virtual machine (JVM) with a time-to-live (TTL) of 60 seconds for DNS name lookups.
AWS SDK for Java Developer Guide Exception Handling • To allow developers fine-grained control over the errors they want to handle without forcing them to handle exceptional cases they aren't concerned about (and making their code overly verbose) • To prevent scalability issues inherent with checked exceptions in large applications In general, checked exceptions work well on small scales, but can become troublesome as applications grow and become more complex.
AWS SDK for Java Developer Guide Logging Logging AWS SDK for Java Calls The AWS SDK for Java is instrumented with Apache Commons Logging, which is an abstraction layer that enables the use of any one of a number of logging systems at runtime. Supported logging systems include the Java Logging Framework and Apache Log4j, among others. This topic explains how to use Log4j. You can learn more about Log4j on the Log4j page at the Apache website.
AWS SDK for Java Developer Guide Request/Response Summary Logging log4j.rootLogger=WARN, A1 log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n # Or you can explicitly enable WARN and ERROR messages for the AWS Java clients log4j.logger.com.
AWS SDK for Java Developer Guide Access Control Policies 4 logger. Enabling the DEBUG level on the apache.http.wire logger enables logging for all request and response data. The following log4j.properties file turns on full wire logging in Apache HttpClient 4 and should only be turned on temporarily since it can have a significant performance impact on your application. log4j.rootLogger=WARN, A1 log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.
AWS SDK for Java Developer Guide Access Control Policies .withResources(new S3ObjectResource(myBucketName, "*")); Statement allowRestrictedWriteStatement = new Statement(Effect.Allow) .withPrincipals(new Principal("123456789"), new Principal("876543210")) .withActions(S3Actions.PutObject) .withResources(new S3ObjectResource(myBucketName, "*")); Policy policy = new Policy() .withStatements(allowPublicReadStatement, allowRestrictedWriteStatement); AmazonS3 s3 = new AmazonS3Client(myAwsCredentials); s3.
AWS SDK for Java Developer Guide Access Control Policies .withActions(SNSActions.Subscribe) .withConditions(endpointCondition)); AmazonSNS sns = new AmazonSNSClient(myAwsCredentials); sns.setTopicAttributes( new SetTopicAttributesRequest(myTopicArn, "Policy", policy.toJson())); Version v1.0.
AWS SDK for Java Developer Guide DynamoDB Using Amazon Web Services with the AWS SDK for Java This section provides information about how to program various Amazon Web Services using the SDK for Java. Topics • Programming DynamoDB with the AWS SDK for Java (p. 20) • Programming Amazon EC2 with the AWS SDK for Java (p. 23) • Programming Amazon SWF with the AWS SDK for Java (p.
AWS SDK for Java Developer Guide Manage Tomcat Session State with DynamoDB Downloading the Session Manager You can download the session manager from the aws/aws-dynamodb-session-tomcat project on GitHub. That project also hosts the session manager source code if you want to contribute to the project by sending us pull requests or opening issues.
AWS SDK for Java Developer Guide Manage Tomcat Session State with DynamoDB • A config file that copies the jar into Tomcat's lib directory and applies the overridden context.xml file. You can find in more information on customizing the AWS Elastic Beanstalk environments in the developer guide for that service.
AWS SDK for Java Developer Guide Amazon EC2 Troubleshooting If you encounter issues with the session manager, the first place to look is in catalina.out. If you have access to the Tomcat installation, you can go directly to this log file and look for any error messages from the session manager. If you're using AWS Elastic Beanstalk, you can view the environment logs with the AWS Management Console or the AWS Toolkit for Eclipse. Limitations The session manager does not support session locking.
AWS SDK for Java Developer Guide Starting an Amazon EC2 Instance 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.
AWS SDK for Java Developer Guide Starting an Amazon EC2 Instance If you want to allow inbound traffic, create a security group and assign a rule to it that allows the ingress that you want. Then associate the new security group with an Amazon EC2 instance. For more information, see Authorize Security Group Ingress (p. 25). To create an Amazon EC2 security group 1. Create and initialize a CreateSecurityGroupRequest instance.
AWS SDK for Java Developer Guide Starting an Amazon EC2 Instance IpPermission ipPermission = new IpPermission(); ipPermission.withIpRanges("111.111.111.111/32", "150.150.150.150/32") .withIpProtocol("tcp") .withFromPort(22) .withToPort(22); All the conditions that you specify in the IpPermission object must be met in order for ingress to be allowed. 2. Specify the IP address using CIDR notation. If you specify the protocol as TCP/UDP, you must provide a source port and a destination port.
AWS SDK for Java Developer Guide Starting an Amazon EC2 Instance To create a key pair and obtain the private key 1. Create and initialize a CreateKeyPairRequest instance. Use the withKeyName method to set the key pair name, as follows: CreateKeyPairRequest createKeyPairRequest = new CreateKeyPairRequest(); createKeyPairRequest.withKeyName(keyName); 2. Pass the request object to the createKeyPair method.
AWS SDK for Java Developer Guide Starting an Amazon EC2 Instance 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.
AWS SDK for Java Developer Guide Using IAM Roles for EC2 Instances Related Resources The following table lists related resources that you'll find useful when using Amazon EC2 with the AWS SDK for Java. Resource Description Java Developer Center Provides sample code, documentation, tools, and additional resources to help you build applications on Amazon Web Services. AWS SDK for Java Documentation Provides documentation for the AWS SDK for Java.
AWS SDK for Java Developer Guide Using IAM Roles for EC2 Instances Using IAM Roles with the SDK for Java If your application creates an AWS client using its default constructor (by providing the constructor with no arguments), then the SDK for Java will search for credentials, in order, in the following places: 1. In the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. 2. In the Java system properties aws.accessKeyId and aws.secretKey. 3. From the Instance Metadata Service (IMDS).
AWS SDK for Java Developer Guide Using IAM Roles for EC2 Instances To create the IAM role to give S3 read-only access to your EC2 instance 1. Log in to the AWS Management Console and go to IAM. 2. 3. Select Roles in the left sidebar and click Create New Role. Provide a memorable name for your role (you'll need to enter its name when you create the EC2 instance, later), and click Continue. 4. The IAM console provides ready-made policy templates for specific AWS services.
AWS SDK for Java Developer Guide Using IAM Roles for EC2 Instances Note Policies can also be represented in JSON format. Here is a policy that provides read ("Get" and "List") access to Amazon S3.
AWS SDK for Java Developer Guide Using IAM Roles for EC2 Instances Create your Application We'll now build the application that will run on the Amazon EC2 instance. First, create a directory that you can use to hold your tutorial files. Call it something like GetS3ObjectApp. Next, copy the SDK for Java libraries into your newly-created tutorial directory. If you downloaded the SDK for Java to your ~/Downloads directory, you can copy them with the following commands: cp -r ~/Downloads/aws-java-sdk-1.7.
AWS SDK for Java Developer Guide Using IAM Roles for EC2 Instances { System.out.println("Downloading an object"); S3Object s3object = s3Client.getObject( new GetObjectRequest(bucketName, key)); displayTextInputStream(s3object.getObjectContent()); } catch(AmazonServiceException ase) { System.out.println( "AmazonServiceException" ); } catch(AmazonClientException ace) { System.out.
AWS SDK for Java Developer Guide Using IAM Roles for EC2 Instances Build and run the modified program. Since no credentials are stored in the program, unless you have your AWS credentials specified in your environment, it's likely that you'll get an AmazonServiceException. For example: $ ant Buildfile: /path/to/my/GetS3ObjectApp/build.
AWS SDK for Java Developer Guide Tutorial: Amazon EC2 Spot Instances ssh -i key-pair-eclipse-1.pem ec2-user@ec2-23-20-56-134.compute-1.amazonaws.com If ant is not installed on the AMI that you selected, you can install it using the yum installer. sudo yum install ant Run the program using ant. ant getS3Object The program should output the contents of your Amazon S3 object to your command window.
AWS SDK for Java Developer Guide Tutorial: Amazon EC2 Spot Instances • Determine when the Spot Request becomes fulfilled • Cancel the Spot Request • Terminate associated instances Prerequisites To use this tutorial you need to be signed up for Amazon Web Services (AWS). If you have not yet signed up for AWS, go to the Amazon Web Services website, and click Create an AWS Account in the upper right corner of the page. In addition, you also need to install the AWS Java SDK.
AWS SDK for Java Developer Guide Tutorial: Amazon EC2 Spot Instances • AWS Security Credentials in AWS General Reference Now that you have configured your settings, you can get started using the code in the example. Step 2: Setting Up a Security Group A security group acts as a firewall that controls the traffic allowed in and out of a group of instances. By default, an instance is started without any security group, which means that all incoming IP traffic, on any TCP port will be denied.
AWS SDK for Java Developer Guide Tutorial: Amazon EC2 Spot Instances // Get IP Address ipAddr = addr.getHostAddress()+"/10"; } catch (UnknownHostException e) { 35 } // Create a range that you would like to populate. ArrayList ipRanges = new ArrayList(); ipRanges.add(ipAddr); 40 // Open up port 22 for TCP traffic to the associated IP // from above (e.g. ssh traffic).
AWS SDK for Java Developer Guide Tutorial: Amazon EC2 Spot Instances 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. There are many ways to approach bidding for Spot instances; to get a broad overview of the various approaches you should view the Bidding for Spot Instances video.
AWS SDK for Java Developer Guide Tutorial: Amazon EC2 Spot Instances LaunchSpecification for the request, which includes the instance type, AMI ID, and security group you want to use. Once the request is populated, you call the requestSpotInstances method on the AmazonEC2Client object. The following example shows how to request a Spot Instance. 1 // Retrieves the credentials from a AWSCrentials.properties file.
AWS SDK for Java Developer Guide Tutorial: Amazon EC2 Spot Instances Step 4: Determining the State of Your Spot Request Next, we want to create code to wait until the Spot request reaches the "active" state before proceeding to the last step. To determine the state of our Spot request, we poll the describeSpotInstanceRequests method for the state of the Spot request ID we want to monitor. The request ID created in Step 2 is embedded in the response to our requestSpotInstances request.
AWS SDK for Java Developer Guide Tutorial: Amazon EC2 Spot Instances 20 25 30 // Look through each request and determine if they are all in // the active state. for (SpotInstanceRequest describeResponse : describeResponses) { // If the state is open, it hasn't changed since we attempted // to request it. There is the potential for it to transition // almost immediately to closed or cancelled so we compare // against open instead of active. if (describeResponse.getState().
AWS SDK for Java Developer Guide Tutorial: Amazon EC2 Spot Instances To terminate any outstanding instances, you will need the instance ID associated with the request that started them. The following code example takes our original code for monitoring the instances and adds an ArrayList in which we store the instance ID associated with the describeInstance response. 1 // Create a variable that will track whether there are any requests // still in the open state. boolean anyOpen; 5 // Initialize variables.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management } } while (anyOpen); Using the instance IDs, stored in the ArrayList, terminate any running instances using the following code snippet. 1 try { // Terminate instances. TerminateInstancesRequest terminateRequest = new TerminateInstances Request(instanceIds); ec2.terminateInstances(terminateRequest); 5 } catch (AmazonServiceException e) { // Write out any exceptions that may have occurred. System.out.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management Spot Instances can significantly lower your Amazon EC2 costs for batch processing, scientific research, image processing, video encoding, data and web crawling, financial analysis, and testing. Additionally, Spot Instances can provide access to large amounts of additional compute capacity when your need for the capacity is not urgent.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management Related topics • What Is IAM? in Using IAM • AWS Security Credentials in AWS General Reference Step 2: Setting Up a Security Group A security group acts as a firewall that controls the traffic allowed in and out of a group of instances. By default, an instance is started without any security group, which means that all incoming IP traffic, on any TCP port will be denied.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management // Get the IP of the current host, so that we can limit the Security Group // by default to the ip range associated with your subnet. 30 try { InetAddress addr = InetAddress.getLocalHost(); // Get IP Address ipAddr = addr.getHostAddress()+"/10"; 35 } catch (UnknownHostException e) { } // Create a range that you would like to populate. ArrayList ipRanges = new ArrayList(); 40 ipRanges.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management 1 // Retrieves the credentials from an AWSCredentials.properties file. AWSCredentials credentials = null; try { 5 credentials = new PropertiesCredentials( GettingStartedApp.class.getResourceAsStream("AwsCredentials.proper ties")); } catch (IOException e1) { System.out.println("Credentials were not properly entered into AwsCre dentials.properties."); System.out.println(e1.getMessage()); 10 System.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management 1 // Retrieves the credentials from an // AWSCredentials.properties file. AWSCredentials credentials = null; 5 try { credentials = new PropertiesCredentials( GettingStartedApp.class.getResourceAsStream("AwsCredentials.proper ties")); } catch (IOException e1) { System.out.println("Credentials were not properly entered into AwsCre dentials.properties."); 10 System.out.println(e1.getMessage()); System.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management 1 // Retrieves the credentials from an AWSCredentials.properties file. AWSCredentials credentials = null; try { 5 credentials = new PropertiesCredentials( GettingStartedApp.class.getResourceAsStream("AwsCredentials.proper ties")); } catch (IOException e1) { System.out.println("Credentials were not properly entered into AwsCre dentials.properties."); System.out.println(e1.getMessage()); 10 System.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management Grouping Your Amazon EC2 Spot Instance Requests You have the option of grouping your Spot instance requests in several different ways. We'll look at the benefits of using launch groups, Availability Zone groups, and placement groups. If you want to ensure your Spot instances are all launched and terminated together, then you have the option to leverage a launch group.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management questRequest); If you want to ensure that all instances within a request are launched in the same Availability Zone, and you don't care which one, you can leverage Availability Zone groups. An Availability Zone group is a label that groups a set of instances together in the same Availability Zone.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management You can specify an Availability Zone that you want for your Spot Instances. The following code example shows you how to set an Availability Zone. 1 // Retrieves the credentials from an AWSCredentials.properties file. AWSCredentials credentials = null; try { 5 credentials = new PropertiesCredentials( GettingStartedApp.class.getResourceAsStream("AwsCredentials.proper ties")); } catch (IOException e1) { System.out.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management with lower latency and high-bandwidth connectivity between the instances. An example of how to set a placement group follows. 1 // Retrieves the credentials from an AWSCredentials.properties file. AWSCredentials credentials = null; try { 5 credentials = new PropertiesCredentials( GettingStartedApp.class.getResourceAsStream("AwsCredentials.proper ties")); } catch (IOException e1) { System.out.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management code examples are combined into one long code sample, which can be found in the com.amazonaws.codesamples.advanced.InlineGettingStartedCodeSampleApp.java class. How to Persist a Root Partition After Interruption or Termination One of the easiest ways to manage interruption of your Spot instances is to ensure that your data is checkpointed to an Amazon Elastic Block Store (Amazon EBS) volume on a regular cadence.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management // Create the block device mapping to describe the root partition. BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping(); blockDeviceMapping.setDeviceName("/dev/sda1"); 40 // Set the delete on termination flag to false. EbsBlockDevice ebs = new EbsBlockDevice(); ebs.setDeleteOnTermination(Boolean.FALSE); blockDeviceMapping.setEbs(ebs); 45 // Add the block device mapping to the block list.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. 15 */ package com.amazonaws.codesamples.advanced; import java.io.IOException; import java.util.ArrayList; 20 import java.util.List; import com.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management //================ Submitting a Request ========================// //==============================================================// // Retrieves the credentials from an AWSCredentials.properties file. AWSCredentials credentials = null; try { credentials = new PropertiesCredentials( GettingStartedApp.class.getResourceAsStream("AwsCredentials.proper 70 ties")); } catch (IOException e1) { 75 System.out.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management // Add all of the request ids to the hashset, so we can // determine when they hit the active state. for (SpotInstanceRequest requestResponse : requestResponses) { System.out.println("Created Spot Request: "+requestResponse.getSpot InstanceRequestId()); spotInstanceRequestIds.add(requestResponse.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management DescribeSpotInstanceRequestsResult describeResult = ec2.describeS potInstanceRequests(describeRequest); 175 List describeResponses = describeResult.get SpotInstanceRequests(); 180 185 190 195 200 205 210 // Look through each request and determine if they are all // in the active state.
AWS SDK for Java Developer Guide Tutorial: Advanced Amazon EC2 Spot Request Management 230 System.out.println("Request ID: " + e.getRequestId()); } 235 //===========================================================// //================== Canceling the Request ==================// //===========================================================// try { // Cancel requests. CancelSpotInstanceRequestsRequest cancelRequest = new CancelSpotIn stanceRequestsRequest(spotInstanceRequestIds); 240 ec2.
AWS SDK for Java Developer Guide Amazon SWF Programming Amazon SWF with the AWS SDK for Java This section provides information specific to programming Amazon SWF with the SDK for Java. Topics • Registering an Amazon SWF Domain Using the AWS SDK for Java (p. 63) • Listing Amazon SWF Domains Using the AWS SDK for Java (p. 63) Registering an Amazon SWF Domain Using the AWS SDK for Java Every workflow and activity in Amazon SWF needs a domain to run in. To register an Amazon SWF domain 1. 2. 3.
AWS SDK for Java Developer Guide Listing Amazon SWF Domains To list Amazon SWF domains 1. Create a ListDomainsRequest object, and specify the registration status of the domains that you're interested in—this is required. 2. Call AmazonSimpleWorkflowClient.listDomains with the ListDomainRequest object. Results are provided in a DomainInfos object. Call getDomainInfos on the returned object to get a list of DomainInfo objects. Call getName on each DomainInfo object to get its name. 3. 4.
AWS SDK for Java Developer Guide Home Page for the AWS SDK for Java Additional Resources This section lists sources of additional information about using Amazon Web Services and the AWS SDK for Java. Topics • Home Page for the AWS SDK for Java (p. 65) • SDK Reference Documentation (p. 65) • AWS Java Developer Blog (p. 65) • AWS Forums (p. 66) • AWS Toolkit for Eclipse (p. 66) • SDK for Java Source Code and Samples (p. 66) • AWS SDK for Java Code Samples (p.
AWS SDK for Java Developer Guide AWS Forums AWS Forums Visit the AWS forums to ask questions or provide feedback about AWS. There is a forum specifically for AWS development in Java as well as forums for individual services such as Amazon S3. AWS engineers monitor the forums and respond to questions, feedback, and issues. You can subscribe to RSS feeds for any of the forums. To visit the AWS forums, visit aws.amazon.
AWS SDK for Java Developer Guide Building and Running the Samples using the Command Line • AmazonEC2SpotInstances-Advanced – demonstrates persistent vs. one-time spot requests, launch groups, and availability groups. • AmazonEC2SpotInstances-GettingStarted – demonstrates how to set up requests for Amazon EC2 Spot Instances, how to determine when they have completed, and how to clean up afterwards. • AmazonKinesis – demonstrates basic use of the Amazon Kinesis client.
AWS SDK for Java Developer Guide Building and Running the Samples using the Eclipse IDE ant The sample prints information to standard output. for example: =========================================== Welcome to the AWS Java SDK! =========================================== You have access to 4 Availability Zones. You have 0 Amazon EC2 instance(s) running. You have 13 Amazon SimpleDB domain(s) containing a total of 62 items.
AWS SDK for Java Developer Guide Building and Running the Samples using the Eclipse IDE To run the project 1. Select the sample .java file you want to run. For example, for the Amazon S3 sample, select S3Sample.java. 2. Select Run from the Run menu. To add the SDK to an existing project 1. Right-click the project in Project Explorer, point to Build Path, and then click Add Libraries. 2. Select AWS Java SDK, and then click Next and follow the remaining on-screen instructions. Version v1.0.
AWS SDK for Java Developer Guide Document History The following table describes the important changes since the last release of the AWS SDK for Java Developer Guide. Last documentation update: May 14, 2014 Change Description Release Date Updated topics The introduction (p. 1) and getting started (p. 4) material May 14, 2014 has been heavily revised to support the new guide structure and now includes guidance about how to Set up your AWS Credentials for Use with the SDK for Java (p. 6).