I made a Slack notification button using the AWS IoT button.
It's a company water server, but the person who used the last one has a flow to notify the general affairs with Slack, but when I get back to my seat, I forget to inform it.
So, I started with the idea of using the IoT button to notify Slack on the spot so that I wouldn't forget it. It's problem-solving driven.
The rest is because there was an AWS IoT button there.
Let's do it!
AWS IoT Button ✕ 1 (¥ 2,500) https://aws.amazon.com/jp/iotbutton/ ~~ It's an Amazon dash button because you see it ~~, this time I will use this. It seems that the Amazon Dash button requires a PC to be a server, isn't it easy to set up and this price is high? So I will use this.
AWS account ✕ 1 (USD $ 0.25 / month) It seems that it costs about 27 yen a month. https://aws.amazon.com/jp/iot-1-click/pricing/
First, register the AwS IoT button. It seems that there is a method of registering from the console and a method of registering with a smartphone, but it seems easy to do with a smartphone.
Install the app from the App Store for iOS or Google Play for Android. I registered on iOS. iOS : https://apps.apple.com/us/app/aws-iot-button/id1178216626 Android : https://play.google.com/store/apps/details?id=com.amazonaws.iotbutton
Log in to AWS to register your device and establish a connection to Wifi. Pochipochi. Pippi. Simply scan the barcode on the side of the AWS IoT button with your camera to register.
I took a screenshot after setting it, but I think it is disabled at first and the project and placement are not set.
Add the Incoming Webhook to your Slack App directory and publish the Webhook URL. Also set the name and icon of the Incoming Webhook to preview the message. ▼ I tried to make it like this
Prepare a script to run using AWS Lambda. The script this time was like this.
require "net/https"
require "uri"
def lambda_handler(event:, context:)
uri = URI.parse('https://hooks.slack.com/services/XXXXXXXXXXX/XXXXXXXXXXX/XXXXXXXXXXXXXXXXXX')
res = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == "https") { |http|
http.request(Net::HTTP::Post.new(uri).tap { |req|
req.body = {
channel: 'The name of the Slack channel you want to be notified of',
username: 'Slack post user name set during webhook',
text: '<@Username of the person to skip the mention>I installed the last one of Aqua Clara.',
}.to_json
})
}
{ statusCode: 200, body: res.to_s }
end
Let's create a test. Anything seems to be fine, so this time I will create it using the settings of the existing template called Hello World, execute it, and check the post to Slack. If you can post to Slack, the code is OK for the time being. Next is the link between Button and AWS.
Finally, create a project that links IoT buttons and Lambda functions from the AWS IoT 1-Click page. Log in to the console and open the AWS IoT 1-Click page. After entering the project name, you can select the device template name and action. Specify the Lambda function you created.
We will specify the device and create a placement. Specify the device and enter the name and value of the attribute
It's OK if it is linked!
This article is based on the following Qiita article. Thanks to you, it has been operating well for more than half a year, which is convenient! https://qiita.com/cumet04/items/11bc8883ae9cc603b84d
Recommended Posts