簡體   English   中英

無法查詢 CloudWatch Log AWS API 端點

[英]Unable to query CloudWatch Log AWS API endpoint

我正在嘗試為我們的內部團隊構建一個小型 Web 應用程序,用於查看我們的 CloudWatch 日志。 現在我還處於開發的早期階段,只是嘗試使用 AWS API 官方文檔中指定的https://logs.us-east-1.amazonaws.com通過 Postman 訪問日志。

我已按照以下步驟設置對端點的 POST 請求,其中包含以下標頭:郵遞員生成的標頭

此外,在文檔之后,我在此帖子請求的正文中提供了操作: {"Action": "DescribeLogGroups"}

使用 AWS CLI 這工作正常,我可以看到我的所有日​​志組。

當我將此請求發送到https://logs.us-east-1.amazonaws.com時,我會回復:

{
    "Output": {
        "__type": "com.amazon.coral.service#UnknownOperationException",
        "message": null
    },
    "Version": "1.0"
}

狀態碼是 200。

我嘗試過的事情:

  • 完全刪除請求正文 -> 導致“內部服務器錯誤”
  • /describeloggroups附加到沒有正文的 URL -> 導致“內部服務器錯誤”

我真的不確定我在這里做錯了什么。

最好的方法是將X-Amz-Target標頭設置為Logs_20140328.DescribeLogGroups

這是一個示例請求: https ://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeLogGroups.html#API_DescribeLogGroups_Example_1_Request

以下是您可以嘗試的 Postman 集合。 將其保存為文件並使用File -> Import Postman。 它還要求您在郵遞員中設置憑據和區域變量。

{
    "info": {
        "name": "CloudWatch Logs",
        "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
    },
    "item": [
        {
            "name": "DescribeLogs",
            "request": {
                "auth": {
                    "type": "awsv4",
                    "awsv4": [
                        {
                            "key": "sessionToken",
                            "value": "{{SESSION_TOKEN}}",
                            "type": "string"
                        },
                        {
                            "key": "service",
                            "value": "logs",
                            "type": "string"
                        },
                        {
                            "key": "region",
                            "value": "{{REGION}}",
                            "type": "string"
                        },
                        {
                            "key": "secretKey",
                            "value": "{{SECRET_ACCESS_KEY}}",
                            "type": "string"
                        },
                        {
                            "key": "accessKey",
                            "value": "{{ACCESS_KEY_ID}}",
                            "type": "string"
                        }
                    ]
                },
                "method": "POST",
                "header": [
                    {
                        "warning": "This is a duplicate header and will be overridden by the Content-Type header generated by Postman.",
                        "key": "Content-Type",
                        "type": "text",
                        "value": "application/json"
                    },
                    {
                        "key": "X-Amz-Target",
                        "type": "text",
                        "value": "Logs_20140328.DescribeLogGroups"
                    },
                    {
                        "warning": "This is a duplicate header and will be overridden by the host header generated by Postman.",
                        "key": "host",
                        "type": "text",
                        "value": "logs.{{REGION}}.amazonaws.com"
                    },
                    {
                        "key": "Accept",
                        "type": "text",
                        "value": "application/json"
                    },
                    {
                        "key": "Content-Encoding",
                        "type": "text",
                        "value": "amz-1.0"
                    }
                ],
                "body": {
                    "mode": "raw",
                    "raw": "{}"
                },
                "url": {
                    "raw": "https://logs.{{REGION}}.amazonaws.com",
                    "protocol": "https",
                    "host": [
                        "logs",
                        "{{REGION}}",
                        "amazonaws",
                        "com"
                    ]
                }
            },
            "response": []
        }
    ],
    "protocolProfileBehavior": {}
}

嘗試將其復制到 json 文件中並將其導入 Postman 並添加缺少的變量。 我試圖在服務“日志”中獲取 DescribeLogGroups。 在此處查看文檔https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeLogGroups.html#API_DescribeLogGroups_Example_1_Request以了解有關標頭和正文的更多信息。 PS:會話令牌是可選的,在我的情況下我不需要它希望它適用於任何人

{
    "info": {
        "_postman_id": "8660f3fc-fc6b-4a71-84ba-739d8b4ea7c2",
        "name": "CloudWatch Logs",
        "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
    },
    "item": [
        {
            "name": "DescribeLogs",
            "request": {
                "auth": {
                    "type": "awsv4",
                    "awsv4": [
                        {
                            "key": "service",
                            "value": "{{AWS_SERVICE_NAME}}",
                            "type": "string"
                        },
                        {
                            "key": "region",
                            "value": "{{AWS_REGION}}",
                            "type": "string"
                        },
                        {
                            "key": "secretKey",
                            "value": "{{AWS_SECRET_ACCESS_KEY}}",
                            "type": "string"
                        },
                        {
                            "key": "accessKey",
                            "value": "{{AWS_ACCESS_KEY_ID}}",
                            "type": "string"
                        },
                        {
                            "key": "sessionToken",
                            "value": "",
                            "type": "string"
                        }
                    ]
                },
                "method": "POST",
                "header": [
                    {
                        "key": "X-Amz-Target",
                        "value": "Logs_20140328.DescribeLogGroups",
                        "type": "text"
                    },
                    {
                        "key": "Content-Encoding",
                        "value": "amz-1.0",
                        "type": "text"
                    }
                ],
                "body": {
                    "mode": "raw",
                    "raw": "{}",
                    "options": {
                        "raw": {
                            "language": "json"
                        }
                    }
                },
                "url": {
                    "raw": "https://{{AWS_SERVICE_NAME}}.{{AWS_REGION}}.amazonaws.com",
                    "protocol": "https",
                    "host": [
                        "{{AWS_SERVICE_NAME}}",
                        "{{AWS_REGION}}",
                        "amazonaws",
                        "com"
                    ]
                }
            },
            "response": []
        }
    ]
}

暫無
暫無

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

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