AWS - Create an AmazonSNSClient

≡放荡痞女 提交于 2019-12-10 11:54:48

问题


I want to create a AmazonSNSClient, I use this piece of code:

AmazonSNSClient snsClient = (AmazonSNSClient) AmazonSNSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(new PropertiesCredentials(is))).build();

but I get this error:

Exception in thread "main" java.lang.UnsupportedOperationException: Client is immutable when created with the builder.

at com.amazonaws.AmazonWebServiceClient.checkMutability(AmazonWebServiceClient.java:937)
at com.amazonaws.AmazonWebServiceClient.setRegion(AmazonWebServiceClient.java:422)


回答1:


It is better if you can put the parameters which you have passed as is or else you can try building the client as below,

If your is is referring to a credential file then you can use the credentials directly with this method,

BasicAWSCredentials basicAwsCredentials = new BasicAWSCredentials(AccessKey,SecretAccessKey);
AmazonSNS snsClient = AmazonSNSClient
                      .builder()
                      .withRegion(your_region)
                      .withCredentials(new AWSStaticCredentialsProvider(basicAwsCredentials))
                      .build();

or else if you are going to give permission through an IAM role then you can use InstanceProfileCredentialProvider like below,

AmazonSNS sns = AmazonSNSClientBuilder
                 .standard()
                 .withCredentials(new InstanceProfileCredentialsProvider(true))
                 .build();


来源:https://stackoverflow.com/questions/51229544/aws-create-an-amazonsnsclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!