gpt4 book ai didi

amazon-web-services - 从 API 网关调用时,Cloudwatch 日志 PutLogEvents 操作失败并显示 com.amazon.coral.service#UnknownOperationException

转载 作者:行者123 更新时间:2023-12-04 00:03:11 29 4
gpt4 key购买 nike

我正在使用 API Gateway 的 AWS 服务集成类型使用 PutLogEvents 操作将日志添加到 Cloudwatch Logs 服务,如下所述:https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutLogEvents.html

我已经成功设置了一种类似类型的方法来使用 PutItem 操作将项目添加到 DynamoDB 表中,并且效果很好,所以我不确定我错过了什么。

我已经仔细检查了我的模板是否存在拼写错误和问题。已使用 CLI 工具成功使用 PutLogEvents,因此设置似乎一切正常。

这是我从 AWS dash 设置的一些屏幕截图:

enter image description here

这是我正在使用的映射模板:

{
"logGroupName": "FromAPI",
"logStreamName": "$input.path('$.streamName')",
"logEvents": [
{
"timestamp": $input.path('$.ts'),
"message": "$input.path('$.message')"
}
]
}

我得到的响应有一个 200 状态代码,但响应正文如下:
{
"Output": {
"__type": "com.amazon.coral.service#UnknownOperationException",
"message": null
},
"Version": "1.0"
}

这是一个经过编辑的 (xxx) 执行日志:
Execution log for request xxx
Fri Apr 19 02:28:58 UTC 2019 : Starting execution for request: xxx
Fri Apr 19 02:28:58 UTC 2019 : HTTP Method: POST, Resource Path: /log
Fri Apr 19 02:28:58 UTC 2019 : Method request path: {}
Fri Apr 19 02:28:58 UTC 2019 : Method request query string: {}
Fri Apr 19 02:28:58 UTC 2019 : Method request headers: {}
Fri Apr 19 02:28:58 UTC 2019 : Method request body before transformations: {
"streamName": "12345",
"ts": 1555641510000,
"message": "help!"
}
Fri Apr 19 02:28:58 UTC 2019 : Endpoint request URI: https://logs.xxx.amazonaws.com/?Action=PutLogEvents
Fri Apr 19 02:28:58 UTC 2019 : Endpoint request headers: {Authorization=xxx, X-Amz-Date=20190419T022858Z, x-amzn-apigateway-api-id=xxx, Accept=application/json, User-Agent=AmazonAPIGateway_xxx, X-Amz-Security-Token=xxx [TRUNCATED]
Fri Apr 19 02:28:58 UTC 2019 : Endpoint request body after transformations: {
"logGroupName": "FromAPI",
"logStreamName": "12345",
"logEvents": [
{
"timestamp": 1555641510000,
"message": "help!"
}
]
}
Fri Apr 19 02:28:58 UTC 2019 : Sending request to https://logs.xxx.amazonaws.com/?Action=PutLogEvents
Fri Apr 19 02:28:58 UTC 2019 : Received response. Status: 200, Integration latency: 38 ms
Fri Apr 19 02:28:58 UTC 2019 : Endpoint response headers: {x-amzn-RequestId=xxx, Content-Type=application/json, Content-Length=105, Date=Fri, 19 Apr 2019 02:28:58 GMT}
Fri Apr 19 02:28:58 UTC 2019 : Endpoint response body before transformations: {"Output":{"__type":"com.amazon.coral.service#UnknownOperationException","message":null},"Version":"1.0"}
Fri Apr 19 02:28:58 UTC 2019 : Method response body after transformations: {"Output":{"__type":"com.amazon.coral.service#UnknownOperationException","message":null},"Version":"1.0"}
Fri Apr 19 02:28:58 UTC 2019 : Method response headers: {X-Amzn-Trace-Id=Root=xxx, Content-Type=application/json}
Fri Apr 19 02:28:58 UTC 2019 : Successfully completed execution
Fri Apr 19 02:28:58 UTC 2019 : Method completed with status: 200


没有任何内容记录到我的 Cloudwatch 日志流中 - API 网关集成请求响应正文包含 UnknownOperationException 错误。

我最好的猜测是这个请求由于某种原因没有映射到 PutLogEvents 操作。奇怪的是,在这种情况下状态代码是 200。

我猜这只是一些错字 - 或者我需要发送的额外标题?有任何想法吗?

最佳答案

如果您在映射模板的顶部添加以下行,它应该可以工作:

#set($context.requestOverride.header['X-Amz-Target'] = "Logs_20140328.PutLogEvents")
#set($context.requestOverride.header['Content-Type'] = "application/x-amz-json-1.1")

这是非常棘手的,并且没有很好的记录。您可以在 sample request for PutLogEvents 中找到这些标题。

关于amazon-web-services - 从 API 网关调用时,Cloudwatch 日志 PutLogEvents 操作失败并显示 com.amazon.coral.service#UnknownOperationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55755935/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com