Skip to content

CloudWatch Dashboard Input Field Filter Widgets

0

Hello!

I’m sending logs from my Android Kotlin application to AWS CloudWatch in JSON format.

The logs are arriving correctly in AWS and I can see them through live tail.

However, I’m creating a dashboard and I’m having trouble making my widget reflect the value entered by the user.

For example, I have an input called employeeId, and I want my widget to only display logs related to that employeeId that was entered.

Is this possible?

This is the JSON of my dashboard at the moment. I read that if you send the log in JSON format, the attributes are automatically converted into indexes by AWS and it works well.

{
    "variables": [
        {
            "type": "property",
            "property": "view",
            "inputType": "input",
            "id": "employee_id_input",
            "label": "employee_id",
            "visible": true
        }
    ],
    "widgets": [
        {
            "type": "log",
            "x": 0,
            "y": 0,
            "width": 24,
            "height": 8,
            "properties": {
                "query": "SOURCE 'OFAKotlinApp' | fields @timestamp, storeId, ofaEmployeeId, orderId, orderType, url, status, @message \n| sort @timestamp desc\n| filter ofaEmployeeId = employee_id_input\n| limit 10000\n",
                "region": "us-east-1",
                "stacked": false,
                "title": "Logs by Employee ID",
                "view": "table"
            }
        }
    ]
}
1 Answer
0

Yes, it is possible to filter CloudWatch logs based on user input using dashboard variables as you're attempting to do. However, there are a few things to check in your implementation:

  1. In your filter statement, you need to ensure you're referencing the variable correctly. Based on your JSON, you've defined a variable with ID "employee_id_input" but in your query, you're using it directly as "employee_id_input". You should reference it using the proper syntax for CloudWatch dashboard variables, which typically uses ${variable_id}.

Try modifying your filter statement to:

filter ofaEmployeeId = ${employee_id_input}
  1. Make sure the field "ofaEmployeeId" is correctly extracted from your JSON logs. If your logs are properly formatted as JSON, CloudWatch should automatically parse these fields.

  2. If you're planning to share this dashboard publicly, be aware that input variables won't work on publicly shared dashboards. When CloudWatch dashboards are shared publicly, they become view-only, and users cannot interact with dashboard variables. This is a limitation of the public sharing feature, which is designed for displaying information rather than interactive use.

If you need users without AWS credentials to interact with the dashboard variables, you might need to consider alternative approaches, such as creating a custom application that interacts with CloudWatch APIs.
Sources
How do you show input variables on publicly shared cloudwatch dashboard | AWS re:Post

answered a year ago

  • filter ofaEmployeeId = ${employee_id_input}

    Token recognition error at: '' token recognition error at: '$' at line 2 and position 25

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.