【问题标题】:Adding TAG to EMR Cluster将 TAG 添加到 EMR 集群
【发布时间】:2014-06-19 02:21:27
【问题描述】:

我正在使用 Java API 启动 emr 集群,但无法将 标签 与其关联。请你帮我解决这个问题。

使用 EMR CLI,如下所示非常简单,但我必须使用我的 Java 代码来完成此操作

./elastic-mapreduce --create --alive --tag tagKey=stackOverflow

如果您需要更多详细信息,请告诉我..

提前致谢。

问候, 维内特

【问题讨论】:

    标签: emr amazon-emr


    【解决方案1】:

    在 EMR Java SDK 的早期版本中,没有添加标签的方法(肯定不是直接的)添加标签,但在 EMR 的 Java SDK 的较新版本中,有一个名为 addTags(Collection<Tag> tags) 的方法,您可以使用它向作为 EMR 集群的一部分启动的资源 (EC2) 添加标签。 您可以按如下方式使用它:

    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    
    AmazonElasticMapReduce emr = new AmazonElasticMapReduceClient(credentials);
    
    List<Tag> tags = new ArrayList<Tag>();
    
    Tag stackOverflowTag = new Tag();
    stackOverflowTag.setKey("stackOverflow");
    
    tags.add(stackOverflowTag);
    AddTagsRequest addTagsRequest = new AddTagsRequest();
    addTagsRequest.setTags(tags);
    
    emr.addTags(addTagsRequest);
    StepFactory stepFactory = new StepFactory();
    // set up the cluster to launch and add steps
    RunJobFlowResult result = emr.runJobFlow(request);
    

    使用 com.amazonaws.services.elasticmapreduce.model.Tag 类来创建标签,因为 SDK 中存在许多 Tag 类,并且有一段时间我也导入了错误的类。

    阅读文档here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-30
      • 1970-01-01
      • 1970-01-01
      • 2019-04-04
      • 1970-01-01
      • 2017-06-24
      相关资源
      最近更新 更多