[英]How can I get list of IAM Roles from EC2 using Java SDK or Amazon API?
There are several notes on how to run Instance with given IAM Role and create one. 关于如何使用给定的IAM角色运行实例并创建实例的几点说明。 But what about retrieving such data from EC2 service using Amazon Client (Java SDK) or http-requests via Amazon API? 但是,如何使用Amazon Client(Java SDK)或通过Amazon API从http请求中检索EC2服务中的此类数据呢? Can I get such list of IAM Roles somehow (they were preliminary created in EC2 console by devOps team, so I must somehow expose them in other web-application)? 是否可以某种方式获得IAM角色的此类列表(它们是由devOps团队在EC2控制台中初步创建的,因此我必须以某种方式在其他Web应用程序中公开它们)? Thanks in advance. 提前致谢。
Okay. 好的。 Seems like AmazonIdentityManagementClient listInstanceProfiles() call does the trick. 似乎AmazonIdentityManagementClient listInstanceProfiles()调用可以解决问题。
Some kind of solution should work. 某种解决方案应该起作用。 Sorry for bother. 很抱歉打扰。
public Collection<String> getIAMRolesRange() {
AmazonIdentityManagementClient identityManagementClient = new AmazonIdentityManagementClient(new BasicAWSCredentials(awsAccount.getAccessKeyId(), awsAccount.getAccessSecret()));
ListInstanceProfilesResult listInstanceProfilesResult = identityManagementClient.listInstanceProfiles();
List<String> iamRoles = new LinkedList<String>();
for(InstanceProfile instanceProfile: listInstanceProfilesResult.getInstanceProfiles()) {
iamRoles.addAll(Collections2.transform(instanceProfile.getRoles(), iamRoleToStringFunction));
}
return iamRoles;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.