Skip to content

Cloudwatch Dashboard Variables in Custom Widgets

1

Hi,

I'm trying to develop a custom widget for a cloudwatch dashboard that uses a dashboard variable: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_dashboard_variables.html

Can you get access to the current variable value in the lambda of a custom dashboard widget? I don't see it in the sample lambda event shown here: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/add_custom_widget_dashboard_about.html

I've printed out the event of a custom widget lambda and don't see any dashboard variable values there. I've also tried to add it to the custom widget parameters via $VARNAME, VARNAME, etc with no success. Maybe it's just not supported yet since dashboard variables are relatively new?

Thanks

1 Answer
1

The values of the variables don't get sent to the custom widget as such. Your custom widget needs to be configured with parameters sent to it - and the variable can change value of those parameters. It works the same way all other widgets work.

Posting your dashboard JSON somewhere would help, I can probably show you how to "fix it"

AWS
answered 3 years ago
  • Thanks I figured it out based on your hint. I just added a parameter with the same name as the dashboard variable as in input to the custom widget.

  • Great, glad you figured it out 👍

  • Hi Any chance, if you can suggest how to fix this, I am trying to achieve same -

    {
        "variables": [
            {
                "type": "property",
                "property": "view",
                "inputType": "select",
                "id": "type",
                "label": "Logs Type",
                "defaultValue": "complete",
                "visible": true,
                "values": [
                    {
                        "value": "pending",
                        "label": "Pending"
                    },
                    {
                        "value": "in_progress",
                        "label": "In Progress"
                    },
                    {
                        "value": "error",
                        "label": "Error"
                    },
                    {
                        "value": "complete",
                        "label": "Complete"
                    }
                ]
            }
        ],
        "widgets": [
            {
                "height": 7,
                "width": 24,
                "y": 0,
                "x": 0,
                "type": "log",
                "properties": {
                    "query": "SOURCE '/aws/lambda/lambda-reporting' | fields jsonParse(@message) as js\n  | display @logStream, js.app, js.status, js.message",
                    "region": "ap-southeast-2",
                    "stacked": false,
                    "view": "table"
                }
            }
        ]
    }
    

    I need this query to be updated based on value of type variable.....

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.