1212Creating Service Clients
1313########################
1414
15- To make requests to |AWSlong |, you first create a service client object. The preferred way to do
16- this is to use the service client builder. Each AWS service has a service interface that has methods
15+ .. meta ::
16+ :description: How to create service clients by using the AWS SDK for Java.
17+ :keywords:
18+
19+ To make requests to |AWSlong |, you first create a service client object. The recommended
20+ way is
21+ to use the service client builder.
22+
23+ Each AWS service has a service interface with methods
1724for each action in the service API. For example, the service interface for |DDBlong | is named
1825:aws-java-class: `AmazonDynamoDB <services/dynamodbv2/AmazonDynamoDB> `. Each service interface has a
1926corresponding client builder you can use to construct an implementation of the service interface.
2027The client builder class for |DDB | is named :aws-java-class: `AmazonDynamoDBClientBuilder
2128<services/dynamodbv2/AmazonDynamoDBClientBuilder> `.
2229
23- To obtain an instance of the client builder, use the static factory method ``standard ``, as shown in
24- the following example.
30+ Obtaining a Client Builder
31+ ==========================
32+
33+ To obtain an instance of the client builder, use the static factory method ``standard ``,
34+ as shown in the following example.
2535
2636.. code-block :: java
2737
2838 AmazonDynamoDBClientBuilder builder = AmazonDynamoDBClientBuilder . standard();
2939
3040
31- Once you obtain a builder, you can customize properties of the client by using many fluent setters
32- in the builder API. For example, you can set a custom region and a custom credentials provider as
41+ Once you have a builder, you can customize the client's properties by using many fluent
42+ setters
43+ in the builder API. For example, you can set a custom region and a custom credentials provider, as
3344follows.
3445
3546.. code-block :: java
@@ -39,14 +50,16 @@ follows.
3950 .withCredentials(new ProfileCredentialsProvider (" myProfile" ))
4051 .build();
4152
42- .. note :: The fluent withXXX methods return the ``builder`` object so that you can chain the method
43- calls for convenience and more readable code. After you configure all the properties you want,
44- you can call the ``build `` method to create the client. Once a client is created, it is immutable
53+ .. note :: The fluent ``withXXX`` methods return the ``builder`` object so that you can chain the
54+ method calls for convenience and for more readable code. After you configure the properties you
55+ want,
56+ you can call the ``build `` method to create the client. Once a client is created, it's immutable
4557 and any calls to ``setRegion `` or ``setEndpoint `` will fail.
4658
4759A builder can create multiple clients with the same configuration. When you're writing your
48- application, be aware that the builder is mutable and not thread-safe. The following code uses the
49- builder as a factory for client instances.
60+ application, be aware that the builder is mutable and not thread-safe.
61+
62+ The following code uses the builder as a factory for client instances.
5063
5164.. code-block :: java
5265
@@ -61,8 +74,8 @@ builder as a factory for client instances.
6174 }
6275 }
6376
64- The builder also exposes fluent setters for :aws-java-class: `ClientConfiguration <ClientConfiguration> `',
65- :aws-java-class: `RequestMetricCollector <metrics/RequestMetricCollector> `, and a custom list of
77+ The builder also exposes fluent setters for :aws-java-class: `ClientConfiguration <ClientConfiguration> `'
78+ and :aws-java-class: `RequestMetricCollector <metrics/RequestMetricCollector> `, and a custom list of
6679:aws-java-class: `RequestHandler2 <handlers/RequestHandler2> `.
6780
6881The following is a complete example that overrides all configurable properties.
@@ -79,8 +92,8 @@ The following is a complete example that overrides all configurable properties.
7992
8093Creating Async Clients
8194===================== =
82- The | sdk- java| also has asynchronous (or async) clients for every service, except for | S3long | . There is also a corresponding async
83- client builder for every service.
95+ The | sdk- java| has asynchronous (or async) clients for every service ( except for | S3 | ), and a corresponding
96+ async client builder for every service.
8497
8598.. topic:: To create an async | DDB | client with the default ExecutorService
8699
@@ -91,8 +104,8 @@ client builder for every service.
91104 .withCredentials(new ProfileCredentialsProvider (" myProfile" ))
92105 .build();
93106
94- In addition to the configuration options that the synchronous (or sync) client builder supports, the
95- async client allows you to set a custom : aws- java- class: `ExecutorFactory < client/ builder/ ExecutorFactory > `
107+ In addition to the configuration options that the synchronous (or sync) client builder supports,
108+ the async client enables you to set a custom : aws- java- class: `ExecutorFactory < client/ builder/ ExecutorFactory > `
96109to change the : classname: `ExecutorService ` that the async client uses. : classname: `ExecutorFactory `
97110is a functional interface, so it interoperates with Java 8 lambda expressions and method references.
98111
@@ -105,15 +118,15 @@ is a functional interface, so it interoperates with Java 8 lambda expressions an
105118 .build();
106119
107120
108- Default Client
109- ==============
121+ Using DefaultClient
122+ ================== =
110123
111- Both the sync and async client builders have another factory method called
124+ Both the sync and async client builders have another factory method named
112125: methodname: `defaultClient`. This method creates a service client with the default configuration,
113- using the default provider chain to load credentials and the AWS region . If either credentials or
114- the region cannot be determined from the environment that the application is running in, the call to
115- : methodname: `defaultClient` will fail . See : doc: `credentials` and : doc: `java- dg- region- selection`
116- for more information on how credentials and region are determined.
126+ using the default provider chain to load credentials and the AWS Region . If credentials or
127+ the region can ' t be determined from the environment that the application is running in, the call to
128+ :methodname:`defaultClient` fails . See :doc:`credentials` and :doc:`java-dg-region-selection`
129+ for more information about how credentials and region are determined.
117130
118131.. topic:: To create a default service client
119132
@@ -127,7 +140,7 @@ Client Lifecycle
127140
128141Service clients in the SDK are thread-safe and, for best performance, you should treat them as
129142long-lived objects. Each client has its own connection pool resource that is shut down when the
130- client is garbage collected. To explicitly shut down a client, you can call the
143+ client is garbage collected. To explicitly shut down a client, call the
131144:methodname:`shutdown` method. After calling :methodname:`shutdown`, all client resources are
132145released and the client is unusable.
133146
0 commit comments