[RUBY] I tried to integrate AWS I oT button and Slack

Introduction

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!

What to prepare

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/

Enable IoT button

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.

Download the app from the Store

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. IMG_6601.PNG IMG_6602.PNG

Log in to the AWS console from your PC and activate it.

I took a screenshot after setting it, but I think it is disabled at first and the project and placement are not set. スクリーンショット 2019-12-11 18.13.44.png

Preparing for Slack integration

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 スクリーンショット 2019-12-16 16.41.19.png

Create a Lambda function

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. スクリーンショット 2019-12-16 16.55.33.png If you can post to Slack, the code is OK for the time being. Next is the link between Button and AWS.

Work with devices on AWS IoT 1-Click pages

Creating a project

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. スクリーンショット 2019-12-26 17.59.41.png After entering the project name, you can select the device template name and action. Specify the Lambda function you created. スクリーンショット 2019-12-26 18.01.09.png

Creating a placement

We will specify the device and create a placement. Specify the device and enter the name and value of the attribute スクリーンショット 2019-12-26 18.16.00.png

Press the button to check Slack integration

It's OK if it is linked!

Reference site

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

I tried to integrate AWS I oT button and Slack
I tried to integrate Docker and Maven / Netbean nicely using Jib
I tried to link grafana and postgres [docker-compose]
I tried to link JavaFX and Spring Framework.
I tried to read and output CSV with Outsystems
I tried to operate SQS using AWS Java SDK
I started MySQL 5.7 with docker-compose and tried to connect
I tried to chew C # (reading and writing files)
I tried to verify yum-cron
I tried to collect and solve Ruby's "class" related problems.
I tried to summarize the basics of kotlin and java
I tried to verify this and that of Spring @ Transactional
I tried to make Java Optional and guard clause coexist
I tried to summarize personally useful apps and development tools (development tools)
I tried to summarize personally useful apps and development tools (Apps)
[Rails] I tried to implement "Like function" using rails and js
Create and integrate Slack App and AWS Lambda (for ruby) in 30 minutes
I tried to chew C # (indexer)
I tried to summarize iOS 14 support
I tried to interact with Java
I tried to explain the method
I tried to see if Koalas and Elasticsearch can work together
I tried to summarize the methods of Java String and StringBuilder
I tried to summarize Java learning (1)
I tried to understand nil guard
I tried to summarize Java 8 now
I tried to chew C # (polymorphism: polymorphism)
I tried to explain Active Hash
I introduced WSL2 + Ubuntu to Window10 and tried using GDC, DMD, LDC
I tried to summarize the key points of gRPC design and development
I tried to make my own transfer guide using OpenTripPlanner and GTFS
I made a virtual currency arbitrage bot and tried to make money
I tried to visualize the access of Lambda → Athena with AWS X-Ray
I introduced OpenAPI (Swagger) to Spring Boot (gradle) and tried various settings
I tried to measure and compare the speed of GraalVM with JMH
I tried to summarize the methods used
I tried to introduce CircleCI 2.0 to Rails app
I tried to summarize Java lambda expressions
I tried to get started with WebAssembly
I tried to solve AOJ's Binary Search
I tried to implement the Iterator pattern
I tried to summarize the Stream API
I tried to build AdoptOpenjdk 11 on CentOS 7
What is Docker? I tried to summarize
I tried to build Ruby 3.0.0 from source
I tried to use Selenium like JQuery
I tried to touch JavaScript Part.2 Object-oriented
I tried to implement ModanShogi with Kinx
I tried to create a portfolio with AWS, Docker, CircleCI, Laravel [with reference link]
A story when I tried to make a video by linking Processing and Resolume
I tried to verify whether it would be fun to combine "programming" and "hobbies".
I built a Java EE environment on AWS and tried running a web application
[JDBC ③] I tried to input from the main method using placeholders and arguments.
I tried to convert JavaBean and XML with Jackson formatter XML in this era
I tried to summarize about JVM / garbage collection
I tried to verify AdoptOpenJDK 11 (11.0.2) with Docker image
I tried to make Basic authentication with Java
I tried to implement polymorphic related in Nogizaka.
I tried to manage struts configuration with Coggle
[Rails] I tried to raise the Rails version from 5.0 to 5.2
I tried to organize the session in Rails