0

I have manually created from aws console a CloudWatch Dashboard which contains few widgets from Log Insights Queries. I want to create the same using code (mainly using serverless package). I have found only this serverless plugin related to cloudwatch dashboard, but it does not create dashboard using log insight query. This AWS CloudWatch Code Example also does not show how we can do the same.

I'm using Typescript for the project

Query Exmaple:

fields @timestamp, @message
| filter @message like /REQUEST_ID_GOES_HERE/
Shadab Faiz
  • 2,380
  • 1
  • 18
  • 28

1 Answers1

0

You can take it as an example to create a dashboard with a widget based on a Log Insights query using the Python Boto3

import boto3
# Create a CloudWatch client
cloudwatch = boto3.client('cloudwatch')

# Define the dashboard body
dashboard_body = {
  "widgets": [
    {
      "type": "logQuery",
      "x": 0,
      "y": 0,
      "width": 12,
      "height": 6,
      "properties": {
        "query": "fields @timestamp, @message | filter @message like /REQUEST_ID_GOES_HERE/"
      }
    }
  ]
}
# Create the dashboard
cloudwatch.put_dashboard(
  DashboardName='Dashboard',
  DashboardBody=json.dumps(dashboard_body)
)
A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103