简体   繁体   中英

Reading CloudWatch log query status in go SDK v2

I'm running a CloudWatch log query through the v2 SDK for Go. I've successfully submitted the query using the StartQuery method, however I can't seem to process the results.

I've got my query ID in a variable (queryID) and am using the GetQueryResults method as follows:

    results, err := svc.GetQueryResults(context.TODO(), &cloudwatchlogs.GetQueryResultsInput{QueryId: queryId,})

How do I actually read the contents? Specifically, I'm looking at the Status field. If I run the query at the command line, this comes back as a string description. According to the SDK docs, this is a bespoke type "QueryStatus", which is defined as a string with enumerated constants .

I've tried comparing to the constant names, eg

if results.Status == cloudwatchlogs.GetQueryResultsOutput.QueryStatus.QueryStatusComplete

but the compiler doesn't accept this. How do I either reference the constants or get to the string value itself?

The QueryStatus type is defined in the separate types package . The Go SDK services are all organised this way.

import "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"

if res.Status == types.QueryStatusComplete {
        fmt.Println("complete!")
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM