英文:
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 = ®gie
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())
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论