我已将EC2角色附加到实例,我的EC2实例,并且我正在运行AWS JAVA SDK.当我尝试以这种方式加载凭据时:
InstanceProfileCredentialsProvider instanceCred = new InstanceProfileCredentialsProvider();
我收到以下错误:
Exception in thread "main" com.amazonaws.AmazonClientException: Unable to load credentials.
at com.amazonaws.auth.InstanceProfileCredentialsProvider.loadCredentials(InstanceProfileCredentialsProvider.java:195)
at com.amazonaws.auth.InstanceProfileCredentialsProvider.getCredentials(InstanceProfileCredentialsProvider.java:124)
可以建议我可能会缺少什么吗?
最佳答案 通过运行我的EC2实例中的代码并增强我的代码,我能够绕过它,这里是代码:
String arn = "arn:aws:iam::"+accountnumber+":role/My-CrossAccount-CustomRole-ReadOnly";
InstanceProfileCredentialsProvider instanceCred = new InstanceProfileCredentialsProvider();
stscred = new STSAssumeRoleSessionCredentialsProvider(instanceCred.getCredentials(),arn,"123",clientConfiguration);
确保角色操作中有“sts:AssumeRole”.