AWS - 创建一个 AmazonSNSClient
AWS - Create an AmazonSNSClient
我想创建一个AmazonSNSClient,我使用这段代码:
AmazonSNSClient snsClient = (AmazonSNSClient) AmazonSNSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(new PropertiesCredentials(is))).build();
但我得到这个错误:
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)
如果你可以把你传递的参数作为 is
更好,否则你可以尝试构建客户端,如下所示,
如果您的 is
指的是凭据文件,那么您可以通过此方法直接使用凭据,
BasicAWSCredentials basicAwsCredentials = new BasicAWSCredentials(AccessKey,SecretAccessKey);
AmazonSNS snsClient = AmazonSNSClient
.builder()
.withRegion(your_region)
.withCredentials(new AWSStaticCredentialsProvider(basicAwsCredentials))
.build();
否则,如果您要通过 IAM 角色授予权限,则可以使用如下所示的 InstanceProfileCredentialProvider,
AmazonSNS sns = AmazonSNSClientBuilder
.standard()
.withCredentials(new InstanceProfileCredentialsProvider(true))
.build();
我想创建一个AmazonSNSClient,我使用这段代码:
AmazonSNSClient snsClient = (AmazonSNSClient) AmazonSNSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(new PropertiesCredentials(is))).build();
但我得到这个错误:
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)
如果你可以把你传递的参数作为 is
更好,否则你可以尝试构建客户端,如下所示,
如果您的 is
指的是凭据文件,那么您可以通过此方法直接使用凭据,
BasicAWSCredentials basicAwsCredentials = new BasicAWSCredentials(AccessKey,SecretAccessKey);
AmazonSNS snsClient = AmazonSNSClient
.builder()
.withRegion(your_region)
.withCredentials(new AWSStaticCredentialsProvider(basicAwsCredentials))
.build();
否则,如果您要通过 IAM 角色授予权限,则可以使用如下所示的 InstanceProfileCredentialProvider,
AmazonSNS sns = AmazonSNSClientBuilder
.standard()
.withCredentials(new InstanceProfileCredentialsProvider(true))
.build();