AWS DevOps & Developer Productivity Blog
Publish Amazon DevOps Guru Insights to Slack Channel
Customers using Amazon DevOps Guru often wants to publish operational insights to chat collaboration platforms, such as Slack and Amazon Chime. Amazon DevOps Guru offers a fully managed AIOps platform service that enables developers and operators to improve application availability and resolve operational issues faster. It minimizes manual effort by leveraging machine learning (ML) powered recommendations. DevOps Guru automatically detects operational insights, predicts impending resource exhaustion, details likely cause, and recommends remediation actions. For customers running critical applications, having access to these operational insights and real-time alerts are key aspects to improve their overall incident remediation processes and maintain operational excellence. Customers use chat collaboration platforms to monitor operational insights and respond to events, which reduces context switching between applications and provides opportunities to respond faster.
This post walks you through how to integrate DevOps Guru with Slack channel to receive notifications for new operational insights detected by DevOps Guru. It doesn’t talk about enabling Amazon DevOps Guru and generating operational insights. You can refer to Gaining operational insights with AIOps using Amazon DevOps Guru to know more about this.
Solution overview
Amazon DevOps Guru integrates with Amazon EventBridge to notify you of events relating to insights and corresponding insight updates. To receive operational insight notifications in Slack channels, you configure routing rules to determine where to send notifications and use pre-defined DevOps Guru patterns to only send notifications or trigger actions that match that pattern. You can select any of the following pre-defined patterns to filter events to trigger actions in a supported AWS resource. For this post, we will send events only for “New Insights Open”.
- DevOps Guru New Insight Open
- DevOps Guru New Anomaly Association
- DevOps Guru Insight Severity Upgraded
- DevOps Guru New Recommendation Created
- DevOps Guru Insight Closed
When EventBridge receives an event from DevOps Guru, the event rule fires and the event notification is sent to Slack channel by using AWS Lambda or AWS Chatbot. Chatbot is easier to configure and deploy. However, if you want more customization, we have also written a Lambda function that allows additional formatting options.
The goal of this tutorial is to show a technical walkthrough of integration of DevOps Guru with Slack using the following options:
- Publish using AWS Lambda
- Publish using AWS Chatbot
Prerequisites
For this walkthrough, you should have the following prerequisites:
- An AWS account
- A Slack channel
- For “Publish using AWS Lambda”, AWS Serverless Application Model (SAM) CLI
- For “Publish using AWS Chatbot”, AWS Command Line Interface (CLI).
- We recommend using AWS Cloud9 to create an environment to get access to the AWS Serverless Application Model (SAM) CLI or AWS Command Line Interface (CLI) from a bash terminal. AWS Cloud9 is a browser-based IDE that provides a development environment in the cloud. While creating the new environment, ensure you choose Linux2 as the operating system. Alternatively, you can use your bash terminal in your favorite IDE, configure your AWS credentials, and install AWS SAM or AWS CLI
Publish using AWS Lambda
In this tutorial, you will perform the following steps:
- Create a Slack Webhook URL
- Launch SAM template to deploy the solution
- Test the solution
Create a Slack Webhook URL
This step configures Slack workflow and creates a Webhook URL used for API call. You will need to have access to add a new channel and app to your Slack Workspace.
- Create a new channel for events (i.e. devopsguru_events).
- Within Slack, click on your workspace name drop-down arrow in the upper left.
- Choose Tools > Workflow Builder.
- Click Create in the upper right-hand corner of the Workflow Builder and give your workflow a name.
- Click Next.
- Click Select next to Webhook.
- Click Add variable and add the following variables one at a time in the Key section. All data types will be text.
-
- text
- account
- region
- startTime
- insightType
- severity
- description
- insightUrl
- numOfAnomalies
- When done, you should have 9 variables, double check them as they are case sensitive and will be referenced.
- Click Add Step.
- On the Add a workflow step window, click Add next to send a message.
- Under Send this message to select the channel you created in earlier step.
- In Message text, create the following.
- Click Save.
- Click Publish.
- For the deployment, we will need the Webhook URL. Copy it in the notepad.
Launch SAM template to deploy the solution
In this step, you will launch the SAM template. This template deploys an AWS Lambda function that is triggered by an Amazon EventBridge rule when Amazon DevOps Guru notifies event relating to “DevOps Guru New Insight Open”. It also deploys AWS Secret Manager, Amazon EventBridge Rule and required permission to invoke this specific function. The AWS Lambda function retrieves the Slack Webhook URL from AWS Secret Manager and posts a message to Slack using webhook API call.
- Create a new directory, navigate to that directory in a terminal and clone the GitHub repository using the below command.
- Change directory to the directory where you cloned the GitHub repository.
- From the command line, use AWS SAM to build the serverless application with its dependencies.
- From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file.
- During the prompts.
-
- enter a stack name.
- enter the desired AWS Region.
- enter the Secret name to store Slack Channel Webhook URL.
- enter the Slack Channel Webhook URL that you copied in an earlier step.
- allow SAM CLI to create IAM roles with the required permissions.
Once you have run sam deploy --guided
mode once and saved arguments to a configuration file (samconfig.toml), you can use sam deploy in future to use these defaults.
Test the solution
- Follow this blog to enable DevOps Guru and generate operational insights.
- When DevOps Guru detects a new insight, it generates events in EventBridge. EventBridge then triggers Lambda that sends it to a Slack channel as below.
Cleaning up
To avoid incurring future charges, delete the resources.
- Delete resources deployed from this blog.
- From the command line, use AWS SAM to delete the serverless application with its dependencies.
Publish using AWS Chatbot
In this tutorial, you will perform the following steps:
- Configure Amazon Simple Notification Service (SNS) and Amazon EventBridge using the AWS Command Line Interface (CLI)
- Configure AWS Chatbot to a Slack workspace
- Test the solution
Configure Amazon SNS and Amazon Eventbridge
We will now configure and deploy an SNS topic and an Eventbridge rule. This EventBridge rule will be triggered by DevOps Guru when “DevOps Guru New Insight Open” events are generated. The event will then be sent to the SNS topic which we will configure as a target for the Eventbridge rule.
- Using CLI, create an SNS topic running the following command in the CLI. Alternatively, you can configure and create an SNS topic in the AWS management console.
- Save the SNS topic ARN that is generated in the CLI for a later step in this walkthrough.
- Now we will create the Eventbridge rule. Run the following command to create the Eventbridge rule. Alternatively, you can configure and create the rule in the AWS management console.
- We now want to add targets to the rule we just created. Use the ARN of the SNS topic we created in step one.
- We now have created an SNS topic, and an Eventbridge rule to send “DevOps Guru New Insight Open” events to that SNS topic.
Create and Add AWS Chatbot to a Slack workspace
In this step, we will configure AWS Chatbot and our Slack channel to receive the SNS Notifications we configured in the previous step.
- Sign into the AWS management console and open AWS Chatbot at https://console.thinkwithwp.com/Chatbot/.
- Under Configure a chat client, select Slack from the dropdown and click Configure Client.
- You will then need to give AWS Chatbot permission to access your workspace, click Allow.
- Once configured, you’ll be redirected to the AWS management console. You’ll now want to click Configure new channel.
- Use the follow configurations for the setup of the Slack channel.
-
- Configuration Name: aws-chatbot-devops-guru
- Channel Type: Public or Private
- If adding Chatbot to a private channel, you will need the Channel ID. One way you can get this is by going to your slack channel and copying the link, the last set of unique characters will be your Channel ID.
- Channel Role: Create an IAM role using a template
- Role name: awschatbot-devops-guru-role
- Policy templates: Notification permissions
- Guardrail Policies: AWS-Chatbot-NotificationsOnly-Policy-5f5dfd95-d198-49b0-8594-68d08aba8ba1
- SNS Topics:
- Region: us-east-1 (Select the region you created the SNS topic in)
- Topics: devops-guru-insights-chatbot-topic
- Click Configure.
- You should now have your slack channel configured for AWS Chatbot.
- Finally, we just need to invite AWS Chatbot to our slack channel.
-
- Type /invite in your slack channel and it will show different options.
- Select Add apps to this channel and invite AWS Chatbot to the channel.
- Now your solution is fully integrated and ready for testing.
Test the solution
- Follow this blog to enable DevOps Guru and generate operational insights.
- When DevOps Guru detects a new insight, it generates events in EventBridge, it will send those events to SNS. AWS Chatbot receives the notification from SNS and publishes the notification to your slack channel.
Cleaning up
To avoid incurring future charges, delete the resources.
- Delete resources deployed from this blog.
- When ready, delete the EventBridge rule, SNS topic, and channel configuration on Chatbot.
Conclusion
In this post, you learned how Amazon DevOps Guru integrates with Amazon EventBridge and publishes insights into Slack channel using AWS Lambda or AWS Chatbot. “Publish using AWS Lambda” option gives more flexibility to customize the message that you want to publish to Slack channel. Using “Publish using AWS Chabot”, you can add AWS Chatbot to your Slack channel in just a few clicks. However, the message is not customizable, unlike the first option. DevOps users can now monitor all reactive and proactive insights into Slack channels. This post talked about publishing new DevOps Guru insight to Slack. However, you can expand it to publish other events like new recommendations created, new anomaly associated, insight severity upgraded or insight closed.
About the authors: