package main import ( "fmt" "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/athena" ) func main() { awscfg := &aws.Config{} awscfg.WithRegion("us-east-1") // Create the session that the service will use. sess := session.Must(session.NewSession(awscfg)) svc := athena.New(sess, aws.NewConfig().WithRegion("us-east-1")) var s athena.StartQueryExecutionInput s.SetQueryString("select PageURL from testtable limit 10") var q athena.QueryExecutionContext q.SetDatabase("testdb") s.SetQueryExecutionContext(&q) var r athena.ResultConfiguration r.SetOutputLocation("s3://TestBucket") s.SetResultConfiguration(&r) result, err := svc.StartQueryExecution(&s) if err != nil { fmt.Println(err) return } fmt.Println("StartQueryExecution result:") fmt.Println(result.GoString()) var qri athena.GetQueryExecutionInput qri.SetQueryExecutionId(*result.QueryExecutionId) var qrop *athena.GetQueryExecutionOutput duration := time.Duration(2) * time.Second // Pause for 2 seconds for { qrop, err = svc.GetQueryExecution(&qri) if err != nil { fmt.Println(err) return } if *qrop.QueryExecution.Status.State != "RUNNING" { break } fmt.Println("waiting.") time.Sleep(duration) } if *qrop.QueryExecution.Status.State == "SUCCEEDED" { var ip athena.GetQueryResultsInput ip.SetQueryExecutionId(*result.QueryExecutionId) op, err := svc.GetQueryResults(&ip) if err != nil { fmt.Println(err) return } fmt.Printf("%+v", op) } else { fmt.Println(*qrop.QueryExecution.Status.State) } }