en Peris
en Peris

Reputation: 1717

AWS - Create an AmazonSNSClient

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)

Upvotes: 1

Views: 12639

Answers (1)

SamPiy93
SamPiy93

Reputation: 498

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();

Upvotes: 8

Related Questions