AWS学习番外篇之SDK For Java

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Phone_1070333541/article/details/80760147

一、服务客户端。

每个AWS服务都有一个服务接口,提供了与服务API 中对应的方法。如:Amazon DynamoDB的服务接口名是AmazonDynamoDB。每个服务接口都有对应的客户端生成器,用于构建服务接口。

二、获取客户端生成器。

1.获取客户端生成器的实例,使用静态工厂方法standard。

AmazonDynamoDBClientBuilder builder = AmazonDynamoDBClientBuilder.standard();

2.可以自定义客户端属性。

  • 下面是所有客户自定义的示例。
AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.standard()
        .withRegion(Regions.US_WEST_2)
        .withCredentials(new ProfileCredentialsProvider("myProfile"))
        .withClientConfiguration(new ClientConfiguration().withRequestTimeout(5000))
        .withMetricsCollector(new MyCustomMetricsCollector())
        .withRequestHandlers(new MyCustomRequestHandler(), new MyOtherCustomRequestHandler)
        .build();

3.关闭客户端。
调用shutdown方法。

4.myProfile文件。(凭证)
设置配置命令:set AWS_PROFILE=”myProfile”
设置以后可以使用默认的凭证来实例化客户端。
AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();

5.明确指定凭证

  1. 实例化一个提供了AWSCredentials接口的类,例如:BasicAWSCreentials。
    BasicAWSCredentials awsCreds= new basicAWSCredentials("公钥","私钥");
  2. 使用 AWSCredentals对象创建AWSStatic CredentialsPRovider
  3. 使用AWSStaticCredentialsProcider构建。
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withCredentials (new AWSStaticCredentialsProvider(aesCreds))
.build();

猜你喜欢

转载自blog.csdn.net/Phone_1070333541/article/details/80760147