Short description
To receive notifications when data from indices meet specific conditions, configure alerts in OpenSearch Service.
Note: To receive alerts, you must have OpenSearch Service version 6.2 or later.
To set up the destination and AWS Identity and Access Management (IAM) roles for the OpenSearch Service, use one of the following methods:
- Create a new Amazon SNS destination
- Update an existing Amazon SNS destination
- Create an alert with an Amazon SNS destination
Note: Starting with OpenSearch version 2.0, notification channels replaced alerting destinations. Destinations are officially deprecated and all notification alerts are now managed through channels. The following resolution isn't applicable with OpenSearch version 2.0.
Resolution
Create a new Amazon SNS destination
1. Open the OpenSearch Service console, and then navigate to the Dev Tools dashboard.
Note: If you receive errors when running AWS Command Line Interface (AWS CLI) commands, make sure that you're running the most recent AWS CLI version.
2. Run the following command to create a new Amazon SNS destination:
POST _plugins/_alerting/destinations
Example output:
{
"name": "{example_dest_name}",
"type": "sns",
"sns": {
"topic_arn": "{example_topic_arn}",
"role_arn": "{example_role_arn}"
}
}
Update an existing Amazon SNS destination
1. Open the OpenSearch Service console, and then navigate to the Dev Tools dashboard.
2. Run the following command to edit an existing Amazon SNS destination. For more information, see Update destination on the OpenSearch website.
PUT _plugins/_alerting/destinations
Example output:
{
"name": "{DEST_NAME}",
"type": "sns",
"sns": {
"topic_arn": "{TOPIC_ARN}",
"role_arn": "{ROLE_ARN}"
}
}
Create an alert with an Amazon SNS destination
1. Open the OpenSearch Service console, and then navigate to the Dev Tools dashboard.
2. Run the following command to get the Amazon SNS destination ID. For more information, see Get destination on the OpenSearch website.
GET _plugins/_alerting/destinations
3. Run the following command to get the existing monitor data. Replace example_monitor_id with the ID of the monitor that you created.
GET _plugins/_alerting/monitors/{example_monitor_id}
Example output:
{
"_id" : "example_id",
"_version" : 1,
"_seq_no" : 0,
"_primary_term" : 1,
"monitor" : {
"type" : "monitor",
"schema_version" : 4,
"name" : "example-monitor-name",
"monitor_type" : "query_level_monitor",
"enabled" : true,
"enabled_time" : 1642050259455,
"schedule" : {
"period" : {
"interval" : 1,
"unit" : "MINUTES"
}
},
"inputs" : [...],
"triggers" : [
{
"query_level_trigger" : {
"id" : "example-id",
"name" : "example-name",
"severity" : "2",
"condition" : {
"script" : {
"source" : "ctx.results[0].hits.total .value < 10",
"lang" : "painless"
}
},
"actions" : [ ]
}
}
],
"last_update_time" : example-time
}
Note: To use an Amazon SNS destination in a monitor alert, update an existing monitor to include the Amazon SNS destination within an alert.
4. Use the output values from the preceding step 2 and step 3 commands, and then run the following commands:
Note: Replace the example values with your values.
{
"name": "sns-action",
"destination_id": "{example_SNS_DESTINATION_ID}",
"subject_template": {
"source": "example-message-subject",
"lang": "mustache"
},
"message_template": {
"source": "example-message-body",
"lang": "mustache"
}
}]
}
Run the following command to update the monitor with a notification to the Amazon SNS destination:
PUT _plugins/_alerting/monitors/{example_monitor_id}
Example output:
{
"type": "monitor",
"schema_version": 4,
"name": "example-monitor-name",
"monitor_type": "query_level_monitor",
"enabled": true,
"enabled_time": 1642050259455,
"schedule": {
"period": {
"interval": 1,
"unit": "MINUTES"
}
},
"inputs": [
{...}
],
"triggers": [
{
"query_level_trigger": {
"id": "example-id",
"name": "example-name",
"severity": "2",
"condition": {
"script": {
"source": "ctx.results[0].hits.total .value < 10",
"lang": "painless"
}
},
"actions": [
{
"name": "sns-action",
"destination_id": {example_SNS_DESTINATION_ID},
"subject_template": {
"source": "My Message Subject",
"lang": "mustache"
},
"message_template": {
"source": "This is my message body.",
"lang": "mustache"
}
}
]
}
}
],
"last_update_time": 1642050259456
}
Note: After you set the Amazon SNS destination, the Edit monitor page crashes. To verify the Amazon SNS destination is in use, run the GET monitor command from step 3.