dskyx46424 2016-03-24 09:30
浏览 134
已采纳

如何使用适用于Go的AWS开发工具包创建EMR集群

I want to create EMR clusters using AWS SDK for Go, but I can't find a way in the official documentation.

Package: emr — AWS SDK for Go

Cound you please help me with a detailed code?

  • 写回答

1条回答 默认 最新

  • doupa8922 2016-05-10 07:08
    关注

    Actually, coming up to the same problem, there is a way which is described in the documentation. For me, it was not straightforward as well because the wording is different. It appears that a "running a job flow" is basically what equals creating a cluster and adding steps to it.

    So what you want is the function RunJobFlow found here:

    https://docs.aws.amazon.com/sdk-for-go/api/service/emr/EMR.html#RunJobFlow-instance_method

    So, a simple code example which creates a cluster without steps is the following (make sure you have correct credentials configured):

    package main
    
    import (
        "fmt"
    
        "github.com/aws/aws-sdk-go/aws"
        "github.com/aws/aws-sdk-go/aws/session"
        "github.com/aws/aws-sdk-go/service/emr"
    )
    
    func main() {
        sess := session.New(&aws.Config{Region: aws.String("eu-west-1")})
        svc := emr.New(sess)
    
        params := &emr.RunJobFlowInput{
            Instances: &emr.JobFlowInstancesConfig{ // Required
                Ec2KeyName:                    aws.String("keyname"),
                HadoopVersion:                 aws.String("2.7.2"),
                InstanceCount:                 aws.Int64(1),
                KeepJobFlowAliveWhenNoSteps: aws.Bool(true),
                MasterInstanceType:          aws.String("m1.medium"),
                Placement: &emr.PlacementType{
                    AvailabilityZone: aws.String("eu-west-1a"), // Required
                },
                TerminationProtected:       aws.Bool(true),
            },
            Name:           aws.String("Go Test Cluster"), // Required
            Applications: []*emr.Application{
                { // Required
                    Name:    aws.String("Ganglia"),
                },
                { 
                    Name: aws.String("Spark"),
                },
                // More values...
            },
            JobFlowRole: aws.String("EMR_EC2_DefaultRole"),
            LogUri:      aws.String("s3://aws-logs-0000000000-eu-west-1/elasticmapreduce/"),
            ReleaseLabel: aws.String("emr-4.6.0"),
            ServiceRole:  aws.String("EMR_DefaultRole"),
            VisibleToAllUsers: aws.Bool(true),
        }
        resp, err := svc.RunJobFlow(params)
    
        if err != nil {
            // Print the error, cast err to awserr.Error to get the Code and
            // Message from an error.
            fmt.Println(err.Error())
            return
        }
    
        // Pretty-print the response data.
        fmt.Println(resp)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?