在使用withCredentials方法时,请确保导入AWS SDK的正确版本。在AWS SDK for Java 2.0中,AWSSecutityTokenServiceClientBuilder类不再使用withCredentials方法来配置AWS凭证。取而代之的是withCredentialsProvider和withClientConfiguration方法。使用这些方法中的一个来设置认证凭据。以下是一个示例代码片段:
// 构建STS客户端
public AWSSecurityTokenService stsClient(String profile) {
switch (profile) {
case "default":
return AWSSecurityTokenServiceClientBuilder.standard()
.withCredentials(DefaultAWSCredentialsProviderChain.getInstance())
.withRegion(Regions.DEFAULT_REGION).build();
default:
...
break;
}
}
上一篇:AWSSecurityTokenService 状态码 403 错误
下一篇:AWSSecurityTokenServiceClientBuilder无法解决方法“withCredentials”。