

# Using the AWS SDK for Java 2.x
<a name="using"></a>

This chapter shows you how to use the AWS SDK for Java 2.x effectively. Learn to create service clients, make requests, handle responses, and manage errors. The chapter covers synchronous and asynchronous programming, paginated results, waiters for resource monitoring, and performance optimization. 

You'll also find best practices for client reuse, troubleshooting guidance, Lambda startup optimization, HTTP/2 support, and DNS configuration.

**Contents**
+ [Making AWS service requests using the AWS SDK for Java 2.x](work-witih-clients.md)
  + [Using service clients to make requests](work-witih-clients.md#using-service-client)
    + [Create a service client](work-witih-clients.md#work-with-clients-create)
    + [Default client configuration](work-witih-clients.md#using-default-client)
    + [Configure service clients](work-witih-clients.md#using-configure-service-clients)
    + [Close the service client](work-witih-clients.md#using-closing-client)
  + [Make requests](work-witih-clients.md#using-making-requests)
    + [Use requests to override client configuration](work-witih-clients.md#using-override-client-config-request)
  + [Handle responses](work-witih-clients.md#using-handling-responses)
+ [Programming asynchronously using the AWS SDK for Java 2.x](asynchronous.md)
  + [Use asynchronous client APIs](asynchronous.md#basics-async-non-streaming)
  + [Handle streaming in asynchronous methods](asynchronous.md#basics-async-streaming)
  + [Configure advanced asynchronous options](asynchronous.md#advanced-operations)
+ [Best practices for using the AWS SDK for Java 2.x](best-practices.md)
  + [Prevent hanging requests by configuring API timeouts](best-practices.md#bestpractice5)
  + [Improve performance by reusing service clients](best-practices.md#bestpractice1)
  + [Prevent resource leaks by closing unused service clients](best-practices.md#bestpractice-close-client)
  + [Prevent connection pool exhaustion by closing input streams](best-practices.md#bestpractice2)
  + [Optimize HTTP performance for your application workload](best-practices.md#bestpractice3)
  + [Improve SSL performance with OpenSSL for async clients](best-practices.md#bestpractice4)
  + [Monitor application performance with SDK metrics](best-practices.md#bestpractice6)
+ [Handling errors in the AWS SDK for Java 2.x](handling-exceptions.md)
  + [Why unchecked exceptions?](handling-exceptions.md#why-unchecked-exceptions)
  + [AwsServiceException (and subclasses)](handling-exceptions.md#sdkserviceexception-and-subclasses)
  + [SdkClientException](handling-exceptions.md#sdkclientexception)
  + [Exceptions and retry behavior](handling-exceptions.md#retried-exceptions)
+ [Using paginated results in the AWS SDK for Java 2.x](pagination.md)
  + [Synchronous pagination](pagination.md#synchronous-pagination)
    + [Iterate over pages](pagination.md#iterate-pages)
    + [Iterate over objects](pagination.md#iterate-objects)
      + [Use a stream](pagination.md#use-a-stream)
      + [Use a for-each loop](pagination.md#for-loop)
    + [Manual pagination](pagination.md#manual-pagination)
  + [Asynchronous pagination](pagination.md#asynchronous-pagination)
    + [Iterate over pages of table names](pagination.md#iterate-pages-async)
      + [Use a `Subscriber`](pagination.md#use-a-subscriber)
      + [Use a `Consumer`](pagination.md#id1pagination)
    + [Iterate over table names](pagination.md#iterate-objects-async)
      + [Use a `Subscriber`](pagination.md#id2)
      + [Use a `Consumer`](pagination.md#for-loop-async)
    + [Use third-party library](pagination.md#use-third-party-library)
+ [Using waiters in the AWS SDK for Java 2.x](waiters.md)
  + [Prerequisites](waiters.md#prerequisiteswaiters)
  + [Using waiters](waiters.md#id1waiters)
    + [Synchronous programming](waiters.md#synchronous-programming)
    + [Asynchronous programming](waiters.md#asynchronous-programming)
  + [Configure waiters](waiters.md#configuring-waiters)
    + [Configure a waiter](waiters.md#configure-a-waiter)
    + [Override configuration for a specific request](waiters.md#override-configuration-for-a-specific-request)
  + [Code examples](waiters.md#code-examples)
+ [Troubleshooting FAQs](troubleshooting.md)
  + [How do I fix "`java.net.SocketException`: Connection reset" or "server failed to complete the response" error?](troubleshooting.md#faq-socketexception)
  + [How do I fix "connection timeout"?](troubleshooting.md#faq-connection-timeout)
  + [How do I fix "`java.net.SocketTimeoutException`: Read timed out"?](troubleshooting.md#faq-socket-timeout)
  + [How do I fix "Unable to execute HTTP request: Timeout waiting for connection from pool" error?](troubleshooting.md#faq-pool-timeout)
  + [How do I fix a `NoClassDefFoundError`, `NoSuchMethodError` or `NoSuchFieldError`?](troubleshooting.md#faq-classpath-errors)
  + [How do I fix a "`SignatureDoesNotMatch`" error or "The request signature we calculated does not match the signature you provided" error?](troubleshooting.md#faq-signature-does-not-match-error)
  + [How do I fix "`java.lang.IllegalStateException`: Connection pool shut down" error?](troubleshooting.md#faq-connection-pool-shutdown-exception)
  + [How do I fix "Unable to load credentials from any of the providers in the chain AwsCredentialsProviderChain"?](troubleshooting.md#faq-credentials-provider-chain)
    + [Common causes and solutions](troubleshooting.md#faq-cred-provider-chain-common-causes-and-solutions)
      + [Review your credential configuration](troubleshooting.md#faq-cred-provider-chain-check-config)
        + [For Amazon EC2 instances](troubleshooting.md#faq-cred-check-ec2)
        + [For container environments](troubleshooting.md#faq-cred-check-container-env)
        + [For local development](troubleshooting.md#faq-cred-check-local-dev)
        + [For web identity federation](troubleshooting.md#faq-cred-check-web-id-federation)
      + [Network or proxy connectivity issues](troubleshooting.md#faq-credentials-provider-chain-network-issues)
+ [Reduce SDK startup time for AWS Lambda](lambda-optimize-starttime.md)
  + [Use an AWS CRT-based HTTP client](lambda-optimize-starttime.md#lambda-quick-url)
  + [Remove unused HTTP client dependencies](lambda-optimize-starttime.md#lambda-quick-remove-deps)
  + [Configure service clients to shortcut lookups](lambda-optimize-starttime.md#lambda-quick-clients)
  + [Initialize the SDK client outside of the Lambda function handler](lambda-optimize-starttime.md#lambda-quick-initialize)
  + [Minimize dependency injection](lambda-optimize-starttime.md#lambda-quick-di)
  + [Use a Maven Archetype targeting AWS Lambda](lambda-optimize-starttime.md#lambda-quick-maven)
  + [Consider Lambda SnapStart for Java](lambda-optimize-starttime.md#lambda-quick-snapstart)
  + [Version 2.x changes that affect startup time](lambda-optimize-starttime.md#example-client-configuration)
  + [Additional resources](lambda-optimize-starttime.md#lambda-quick-resources)
+ [Implement `ContentStreamProvider` in the AWS SDK for Java 2.x](content-stream-provider.md)
  + [Use `mark()` and `reset()`](content-stream-provider.md#csp-impl-mark-reset)
  + [Use buffering if `mark()` and `reset()` are not available](content-stream-provider.md#csp-impl-unsupported-streams)
  + [Create new streams](content-stream-provider.md#csp-impl-new-stream)
+ [Set the JVM TTL for DNS name lookups](jvm-ttl-dns.md)
  + [How to set the JVM TTL](jvm-ttl-dns.md#how-to-set-the-jvm-ttl)
    + [Option 1: Set it programmatically in your application](jvm-ttl-dns.md#set-ttl-programmatically)
    + [Option 2: Set it in the java.security file](jvm-ttl-dns.md#set-ttl-java-security-file)
    + [Option 3: Use the JDK system properties fallback (command-line)](jvm-ttl-dns.md#set-ttl-system-property)
+ [Work with HTTP/2 in the AWS SDK for Java](http2.md)