简体   繁体   English

如何使用Java SDK或Amazon API从EC2获取IAM角色列表?

[英]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.

相关问题 如何使用与EC2实例关联的IAM角色从Amazon检索临时AWS凭证(在Java中)? - How to retrieve temporary AWS credentials from Amazon using IAM role associated with the EC2 instance(in java)? 使用 Java 从 Amazon EC2 实例获取信息 SDK - Getting information from an Amazon EC2 instance using Java SDK 从JAVA API获取Amazon EC2实例的公共DNS - Get Public DNS of Amazon EC2 Instance from JAVA API 在java中,如何让Amazon EC2实例查看自己的标签? - In java, how can I get an Amazon EC2 Instance to see its own tags? 如何在 AWS Java SDK 中使用 IAM 角色创建云形成? - How to create cloud formation using IAM roles in AWS Java SDK? 如何将图像文件从amazon s3移动到amazon ec2并使用java运行实例 - How to move an image file from amazon s3 to amazon ec2 and run the instance using java 在使用分配的 IAM 进行访问的 ec2 上使用 java SDK 在 aws 中扮演不同的角色 - assume different role in aws using java SDK on ec2 which uses assigned IAM for access 如何使用Java Apache FTPClient将文件从一个Amazon EC2实例下载到另一个EC2实例 - How to download file from one Amazon EC2 instance to another EC2 instance using java apache FTPClient API 访问 Amazon EC2 价目表? - API access to Amazon EC2 price list? 如何在EC2 Amazon中获取Java线程转储:找不到jstack - How to get Java thread dump in EC2 Amazon : No jstack found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM