list emr clusters using go

huangapple go评论80阅读模式
英文:

list emr clusters using go

问题

我正在尝试使用Go列出EMR集群。

以下是我编写的代码,但返回的结果为空。我在Python中使用相同的代码可以得到正确的结果。

running := "RUNNING"
waiting := "WAITING"
emr_states := []*string{&running, &waiting}

var abc emr.ListClustersInput
abc.SetClusterStates(emr_states)

sess := session.Must(session.NewSession())
svc := emr.New(sess)

list_clusters_output, err := svc.ListClusters(&abc)
_ = err

println(fmt.Sprintf("type of list clusters output is %s", reflect.TypeOf(list_clusters_output)))
println(fmt.Sprintf("type of *list clusters output is %s", reflect.TypeOf(*list_clusters_output)))

list_clusters_output_dereffed := *list_clusters_output
println(list_clusters_output_dereffed.String())

我得到的输出是:

type of list clusters output is *emr.ListClustersOutput
type of *list clusters output is emr.ListClustersOutput
{
}

我成功使用Python脚本返回了一个正在运行的集群。

英文:

I'm trying to list emr clusters using go.

Here is the code I have that is returning blank. I did "the same" in python with correct results.

running := "RUNNING"

waiting := "WAITING"

emr_states := []*string {&running, &waiting}

var abc emr.ListClustersInput

abc.SetClusterStates(emr_states)

sess := session.Must(session.NewSession())

svc := emr.New(sess)

list_clusters_output, err := svc.ListClusters(&abc)

_ = err


println(fmt.Sprintf("type of list clusters output is %s", reflect.TypeOf(list_clusters_output)))

println(fmt.Sprintf("type of *list clusters output is %s", reflect.TypeOf(*list_clusters_output)))


list_clusters_output_dereffed := *list_clusters_output

println(list_clusters_output_dereffed.String())

The output I'm getting is

type of list clusters output is *emr.ListClustersOutput
type of *list clusters output is emr.ListClustersOutput
{
}

There is a cluster running that I have successfully returned with a python script.

答案1

得分: 1

找到了。我在会话中缺少区域指示。

完整的解决方案如下。

package main

import (
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/emr"	
)

func main() {

	starting := "STARTING"

	running := "RUNNING"

	waiting := "WAITING"

	emr_states := []*string {&starting, &running, &waiting}
	
	var abc emr.ListClustersInput
	
	abc.SetClusterStates(emr_states)

	sess := session.Must(session.NewSession())

	reggie := "us-east-1"

	sess.Config.Region = &reggie

	svc := emr.New(sess)

	list_clusters_output, err := svc.ListClusters(&abc)

	if err != nil {
		println(err.Error())
	}

	list_clusters_output_dereffed := *list_clusters_output

	println(list_clusters_output_dereffed.GoString())
	
}
英文:

Figured it out. I was missing region indication in the session.

Full solution below.

package main

import (
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/emr"	
)

func main() {

	starting := "STARTING"

	running := "RUNNING"

	waiting := "WAITING"

	emr_states := []*string {&starting, &running, &waiting}
	
	var abc emr.ListClustersInput
	
	abc.SetClusterStates(emr_states)

	sess := session.Must(session.NewSession())

	reggie := "us-east-1"

	sess.Config.Region = &reggie

	svc := emr.New(sess)

	list_clusters_output, err := svc.ListClusters(&abc)

	if err != nil {
		println(err.Error())
	}

	list_clusters_output_dereffed := *list_clusters_output

	println(list_clusters_output_dereffed.GoString())
	
}

huangapple
  • 本文由 发表于 2022年7月29日 04:10:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/73158656.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定