Kolton Starr
Kolton Starr

Reputation: 11

Unable to query CloudWatch Log AWS API endpoint

I am attempting to build a small web application for our internal team to use to view our CloudWatch logs. Right now I'm very early in development and simply trying to access the logs via Postman using https://logs.us-east-1.amazonaws.com as specified in the AWS API official documentation.

I have followed the steps to set up my POST request to the endpoint with the following headers: Postman Generated Headers

Also, in following with the documentation I have provided the Action in the body of this post request: {"Action": "DescribeLogGroups"}

Using the AWS CLI this works fine and I can see all my logs groups.

When I send this request to https://logs.us-east-1.amazonaws.com I get back:

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

The status code is 200.

Things I have tried:

I'm truly not sure what I'm doing wrong here.

Upvotes: 1

Views: 1516

Answers (3)

Jonas Bergkvist
Jonas Bergkvist

Reputation: 1

You guys helped me figure out what i was doing wrong, thanks! Now, i didn't try to download the file and import it (suggested above) because i had already set things up in Postman. I saw however that i was missing header "Content-Encoding" "amz-1.0". Then it worked. Can't believe it! :)

Upvotes: 0

Omar Ghayor
Omar Ghayor

Reputation: 11

Try copying this into a json file and import it in Postman and add the missing variables. I tried to get a DescribeLogGroups in the service "logs". Look in the docs here https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeLogGroups.html#API_DescribeLogGroups_Example_1_Request for more information about the headers and body. PS: Session token is optional, I didn't need it in my case Hope it works for anyone who

{
    "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": []
        }
    ]
}

Upvotes: 1

Dejan Peretin
Dejan Peretin

Reputation: 12119

Best way is to set the X-Amz-Target header to Logs_20140328.DescribeLogGroups.

Here is an example request: https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeLogGroups.html#API_DescribeLogGroups_Example_1_Request

Below is a Postman collection you can try. Save it as a file and import into Postman with File -> Import. It also requires you to set credential and region variables in 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": {}
}

Upvotes: 2

Related Questions