簡體   English   中英

從API網關調用時,Cloudwatch Logs PutLogEvents操作失敗,並出現com.amazon.coral.service#UnknownOperationException

[英]Cloudwatch Logs PutLogEvents action fails with com.amazon.coral.service#UnknownOperationException when called from API Gateway

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

我已經成功設置了一種類似類型的方法,可以使用PutItem操作將項目添加到DynamoDB表中,並且效果很好,所以我不確定此方法缺少什么。

我已經仔細檢查過拼寫錯誤和模板問題。 已使用CLI工具成功使用PutLogEvents,因此安裝似乎一切正常。

這是AWS破折號中我的設置​​的一些屏幕截圖:

在此處輸入圖片說明

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

{
  "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 Logs流中-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")

這是非常棘手的,並且沒有充分記錄。 您可以在PutLogEvents示例請求中找到這些標頭。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM