gpt4 book ai didi

amazon-web-services - 如何使用 AWS SDK for Go 创建 EMR 集群

转载 作者:IT王子 更新时间:2023-10-29 01:58:59 27 4
gpt4 key购买 nike

我想使用 AWS SDK for Go 创建 EMR 集群,但我在官方文档中找不到方法。

Package: emr — AWS SDK for Go

能否请您帮我提供详细的代码?

最佳答案

其实遇到同样的问题,文档中有介绍的方法。对我来说,这也不简单,因为措辞不同。看起来“运行作业流”基本上等于创建集群并向其添加步骤。

所以你想要的是函数 RunJobFlow 在这里找到:

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

因此,下面是一个无需步骤即可创建集群的简单代码示例(确保您配置了正确的凭据):

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)
}

关于amazon-web-services - 如何使用 AWS SDK for Go 创建 EMR 集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36196875/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com