AWS Feed
Monitor Amazon EventBridge events in your Slack channels with AWS Chatbot
DevOps teams use chat collaboration platforms such as Slack and Amazon Chime to monitor systems and respond to events. When AWS Chatbot is integrated with Slack and Chime, users can monitor and interact with AWS resources from the chat channels, which reduces context switching between applications. DevOps users now can receive notifications from more than 200 service event types in chat channels through Amazon EventBridge.
In this blog post, I will share the steps for setting up an Amazon EventBridge rule and configuring AWS Chatbot to receive notifications in a Slack channel.
How it works
Amazon EventBridge enables applications to route events from AWS services and other data sources to various destinations such as Amazon Simple Notification Service (Amazon SNS) topics and AWS Lambda functions. To receive service event notifications in chat channels, you configure an SNS topic as a target in the Amazon EventBridge rule and then associate the topic with a chat channel in the AWS Chatbot console. When EventBridge receives an event with an event pattern that matches the event pattern defined in the rule, the event rule fires and the event notification is sent to the configured chat channel.
In this tutorial, you will perform the following steps:
- Create an SNS topic. (optional)
- Configure an EventBridge rule for Amazon Elastic Container Service (Amazon ECS) state change events.
- Create an AWS Chatbot configuration.
- Test the EventBridge rule.
Prerequisites
You will need the following:
- An AWS account.
- A Slack channel with the AWS Chatbot app installed.
- An Amazon ECS cluster.
For this post, you will use an Amazon ECS cluster to demonstrate ECS state change event notification delivery to a Slack channel. You want to receive a notification to the Slack channel every time the ECS cluster state changes so that you can diagnose and fix any issues.
Step 1: Create an Amazon SNS topic
First, create an SNS topic to connect EventBridge with AWS Chatbot. If you already have an SNS topic, you can skip this step.
In the SNS console, choose Topics, and then choose Create topic. Give your topic a descriptive name and keep the other parameters their default.
Step 2: Configure an Amazon EventBridge rule for an ECS state change event
- In the Amazon EventBridge console, choose Rules, and then choose Create Rule.
- Enter a descriptive name for your rule.
- For Define pattern, choose Event pattern.
- Choose pre-defined pattern by service to define a pattern to match events.
- For Service provider, choose AWS.
- For Service name, choose Elastic Container Service (ECS).
Note: Currently, only events from AWS services supported in EventBridge are delivered to the chat channels with AWS Chatbot.
- For Event Type, choose State Change as the type of event to use for this rule. You can optionally choose the detail type and cluster.
Figure 1: Define pattern
- In Select targets, for Target, choose SNS topic as the target to invoke when the ECS state change event triggers this rule.
- For Topic, choose the SNS topic you created in Step 1 of this post.
Figure 2: Select targets
- Complete the rule-creation process with the default settings.
Step 3: Create an AWS Chatbot configuration
Now you are ready to start configuring AWS Chatbot with the chat client.
- In the AWS Chatbot console, choose Configure new client.
- In Configure new client, choose Slack.
The setup wizard redirects you to the Slack OAuth 2.0 - In the top-right corner, choose the Slack workspace to configure, and then choose Agree.Your Slack workspace installs the AWSChatbot Demo Slack app. The AWS account that you used to sign in can now send notifications.
Figure 3: AWS Chatbot requests access to Slack workspace
- From here, Slack redirects you to the Configure Slack Channel Choose the channel in which to receive notifications. You can choose a public channel from the dropdown list or paste the URL or ID of a private channel.To find the URL of your private Slack channel, in Slack’s left sidebar, open the context (right-click) menu on the channel name and choose Copy link. AWS Chatbot can work in a channel only if you add AWS Chatbot app (@aws) to the Slack channel. If the AWS Chatbot app has not been added, from the channel’s Details page, choose Add apps.
- After you choose the Slack channel, under IAM Permissions, use an existing IAM role or create one using a policy template. To receive EventBridge notifications, the role must have notifications permissions.
- Finally, under SNS topics, choose the SNS topic that you created in Step 1. You can select multiple SNS topics from more than one region, granting them all the ability to notify the same Slack channel.
- Choose Configure to complete the configuration.
Step 4: Test the alarm
You can test this setup by manually stopping your ECS tasks or services. This should trigger an alarm and send a notification in your Slack channel.
Figure 4: Notification about ECS task state change
Conclusion
DevOps users can now monitor an expanded range of AWS services in AWS Chatbot-configured chat channels. This integration with Slack and Chime reduces context switching and provides an opportunity to monitor applications and CI/CD workflows from chat channels. For more information on AWS Chatbot support for AWS Services through Amazon EventBridge, see Using AWS Chatbot with other AWS services in AWS Chatbot Administrator guide.
Got any ideas to improve AWS Chatbot? You can send your comments to the AWS Chatbot team by typing @aws feedback <your comments>
in your Slack channel.