0
votes

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:

  • Removing the body of the request altogether -> results in "internal server error"
  • appending /describeloggroups to the URL with no body -> results in "internal server error"

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

2
Please post the request you're making, like the examples on docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/… - kielni

2 Answers

1
votes

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": {}
}
0
votes

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