如何从AmazonSNSClient中删除弃用?

时间:2018-06-16 11:43:19

标签: amazon-web-services aws-sdk amazon-sns

我正在尝试在我的应用程序中配置SNS。对于Aws凭证,我使用的是AmazonSNSClient.My AmazonSNSClient和withRegion已弃用,我该怎么办?

我的代码: -

AWSCredentials awsCredentials = new BasicAWSCredentials(                 “*****************”                 “&安培;&安培;&安培;&安培;&安培;&安培;&安培;&安培;&安培;&安培;&安培;&安培;&安培;&安培;”);

    AWSCredentialsProvider awsCredentialsProvider=new AWSStaticCredentialsProvider ( awsCredentials );

    AmazonSNSClient amazonSNSClient=new AmazonSNSClient ( awsCredentialsProvider )
                                       .withRegion ( Region.getRegion(Regions.AP_SOUTH_1));
    String msg = "this is a t---est";
    PublishRequest publishRequest = new PublishRequest("arn:aws:sns:ap-south-1:000000000000:topic", msg);

    PublishResult publishResult = amazonSNSClient.publish ( publishRequest );

    System.out.println("MessageId - " + publishResult.getMessageId());

1 个答案:

答案 0 :(得分:0)

由于最新的SDK版本已弃用客户端构建器,而不是直接使用客户端构建器。

AmazonSNS sns = AmazonSNSClient.builder()
                    .withRegion("<your region>")
                    .withClientConfiguration(<configuration>)
                    .withCredentials(<your credentials>)
                    .build();