Good vs Evil in the American West

No one wants to meet a weirdo on the road, especially after dark. By the same token, quirky lodging is why we love motel chains. I’m perpetually happy to be off the ground, not camping next to my…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Create a Slack Chat bot using AWS services

Chat bots can interact with users, respond to queries, post notifications and so on. This article will create a rather simple bot, which will post to a Slack channel. The trigger to post to a slack channel will be a high CPU utilization of an EC2 instance.

Once you sign-up on Slack, you can either create a new channel where you want the notifications to be posted to, or, you can post the notifications to the default #general channel.

Now, go to Apps and search for Incoming WebHooks. WebHooks will enable content to be posted on Slack. They use HTTP requests with a JSON payload containing the message and other details.

Add the WebHook, choose the channel, add Incoming WebHook Integration and copy the WebHook URL.

AWS:

CloudWatch graph indicating a breach in CPU utilization threshold breach

2. Now, create a lambda function which will be triggered by the SNS notification in the above created alarm. This lambda function will post the relevant message to the desired Slack Channel. AWS provides a blueprint for this purpose. Search for cloudwatch-alarm-to-slack-python.

3. The WebHook URL can be encrypted and then used inside this lambda function. This function uses AWS KMS to decrypt the encrypted WebHook URL. Create or select and existing execution role, select the SNS notification used in the CloudWatch Alarm and enable the trigger.

4. The python code and instructions are already provided by the lambda blueprint.

Enable EPEL repo, install stress, and, stress!

This command will generate a thread to max out a single CPU core. Essentially, it spawns ‘n’ workers spinning on sqrt() function for x seconds. “cpu” refers to the number of threads used for performing the test.

Since, a single core single thread instance(t2.micro) is being used, this command will max out the CPU.

High CPU utilization notification posted on Slack by the lambda function that subscribes to the SNS topic triggered by CloudWatch Alarm.

If you do not want to wait for the CloudWatch Alarm to trigger, use the below command to alter the alarm state:

Add a comment

Related posts:

The Polygen Ambassador Program

Polygen is a fully decentralized launchpad that drives real innovation with real community. We are looking to expand our team and community even more with the introduction of the ambassador program…

Yawm Ashura

Photographing highly religious events can be quite a fraught undertaking. It’s a personal experience so documenting these days is difficult unless you’re part of the accredited media. But what if…

Intro to Docker with TypeScript

Over the past few years Docker has emerged as one of the most efficient ways to manage and deploy cloud-based web applications☁️ 💻 . While containers have been around since 2008, Docker helped them…