简体   繁体   English

go SDK v2中读取CloudWatch日志查询状态

[英]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.我正在通过 v2 SDK 为 Go 运行 CloudWatch 日志查询。我已经使用 StartQuery 方法成功提交了查询,但是我似乎无法处理结果。

I've got my query ID in a variable (queryID) and am using the GetQueryResults method as follows:我在变量 (queryID) 中获取了我的查询 ID,并且正在使用 GetQueryResults 方法,如下所示:

    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.具体来说,我正在查看 Status 字段。 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 .根据 SDK 文档,这是一个定制类型“QueryStatus”,它被定义为一个带有枚举常量的字符串。

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 . QueryStatus类型在单独的类型 package中定义。 The Go SDK services are all organised this way. Go SDK 服务都是这样组织的。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 Kotlin SDK v2 中的 DynamoDb 中查询 GSI - Cannot query GSI in DynamoDb in Kotlin SDK v2 AWS Golang SDK v2 - 如何将 function 添加到 Go AWS 脚本 - AWS Golang SDK v2 - How to add function to Go AWS script AWS Java SDK V2中的package software.amazon.awssdk.core.auth.policy go在哪里? - Where did the package software.amazon.awssdk.core.auth.policy go in the AWS Java SDK V2? Node.js - 如何继续描述 Cloudwatch 日志查询以获取特定查询的已完成状态 - Node.js - How to keep describing Cloudwatch log queries for Completed status of a specific query Cloudwatch RUM 和 API 网关 v2 / Lambda X 射线追踪 - Cloudwatch RUM and API Gateway v2 / Lambda XRay Tracing KFP SDK v2、v2 命名空间和 v2 兼容模式之间有什么区别? - What is difference between the KFP SDK v2, v2 namespace, and v2 compatible mode? CloudWatch 仪表板和使用无服务器的 Log Insight 查询 - CloudWatch Dashboard with Log Insight Query using Serverless 使用 java sdk v2 调用 sagemaker 推理端点 - Call a sagemaker inference endpoint using the java sdk v2 AWS Cloudwatch Insights 如何使用多个日志组进行查询 - AWS Cloudwatch Insights how to query using multiple log groups 关闭 AWS 中的 IdleConnectionReaper Java SDK v2 - Shutdown IdleConnectionReaper in AWS Java SDK v2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM