I made an Amazon Web Service Dash button

Introduction

awsボタン.jpg

The title is missing. After all, infrastructure engineers nowadays have to be able to do one of the servers with the touch of a button. I tried sniffing the nth decoction packet and picking up the dash button event (python on ubuntu) by just hitting the aws cli like below.

--Amazon EC2 Dash Button (Create EC2 VM) --Aws Lambda Dash Button (invoke lamda)

It is a reproduction of the following reference article. How I Hacked Amazon’s $5 WiFi Button to track Baby Data – Medium

Dash button setup

Easy-to-understand commentary. -> Amazon Dash Button super fast commentary --Qiita

  1. Click the Dash button on amazon to reach your house
  2. Launch the Amazon smartphone app (as per the instruction manual)
  3. Select "Account Service"-> "Dash Terminal Set up a new terminal" from the upper left menu (as per the instruction manual)
  4. Press and hold the Dash button for 6 seconds until the LED turns blue (as per the instruction manual)
  5. "Connect" with the app (as per the instruction manual)
  6. Enter wifi connection information in the app (as per the instruction manual)
  7. Any product (different from the instruction manual)

Pick up Dash button events

Preparing the python environment

$ sudo apt-get install tcpdump python-crypto python-scapy
#I want to use scapy, but I can add this and that

$ pip show scapy
Name: scapy
Version: 2.2.3
Location: /usr/lib/python2.7/dist-packages
Requires:
#OK if scapy can be installed

Get the MAC address of the Dash button

Create and run dash-listen-1.py.

dash-listen-1.py



from scapy.all import *

def arp_display(pkt):
  if pkt[ARP].op == 1: #who-has (request)
    if pkt[ARP].psrc == '0.0.0.0': # ARP Probe
      print "ARP Probe from: " + pkt[ARP].hwsrc

print sniff(prn=arp_display, filter="arp", store=0, count=10)

--Replace ARP Probe if necessary

$ sudo python dash-listen-1.py 
WARNING: No route found for IPv6 destination :: (no default route?)
#Since it is output so far, press the Dash button
ARP Probe from: XX:XX:XX:XX:XX:XX
ARP Probe from: XX:XX:XX:XX:XX:XX
ARP Probe from: XX:XX:XX:XX:XX:XX
^C[]
$ 

Now you can get the MAC address.

Get Dash button event in sample code

Continue to create and run dash-listen-2.py.

dash-listen-2.py



from scapy.all import *
def arp_display(pkt):
  if pkt[ARP].op == 1:
    if pkt[ARP].psrc == '0.0.0.0': # ARP probe as your env
      if pkt[ARP].hwsrc == 'XX:XX:XX:XX:XX:XX': # MAC address as your env 
        print "Amazon dash button Pushed."
        sys.exit()

print sniff(prn=arp_display, filter="arp", store=0, count=10)

--Replace ARP Probe if necessary --Rewrite the MAC address to the one obtained above --"sys.exit ()" picks up packets multiple times as in "Get event with sample code", so it ends after processing the first one.


$ sudo python dash-listen-2.py 
WARNING: No route found for IPv6 destination :: (no default route?)
#Since it is output so far, press the Dash button
Amazon dash button Pushed.
$

Now you can pick up the event.

Amazon Web Service Dash button Well, it's finally the main subject, but in the end, I just replaced the ↑ "print" Amazon dash button Pushed. "" With the aws cli's sloppy command.

The following are the assumptions that have been prepared.

--Introduced aws cli and authenticated with aws configure --ec2 ami is existing (this time it is in the amazon linux library) --lambda function created (and IAM)

I tried Amazon EC2 Dash Button

Create dash-ec2.py.

dash-ec2.py



from scapy.all import *
def arp_display(pkt):
  if pkt[ARP].op == 1: #who-has (request)
    if pkt[ARP].psrc == '0.0.0.0': # ARP probe as your env
      if pkt[ARP].hwsrc == 'XX:XX:XX:XX:XX:XX': # MAC address as your env 
        print "Amazon EC2 dash button Pushed."
        os.system("aws ec2 run-instances --image-id ami-0c11b26d --count 1 --instance-type t2.micro")
        #Just added here(The wording of the print on it is also changed a little)
        sys.exit()

print sniff(prn=arp_display, filter="arp", store=0, count=10)

--Roughly create an instance of EC2 --ami-0c11b26d is a plain guy from amazon linux

Below, the console before execution (no instance) before.png

Then execute.


$ sudo python  dash-ec2.py 
WARNING: No route found for IPv6 destination :: (no default route?)
#Since it is output so far, press the Dash button
Amazon EC2 dash button Pushed.
{
    "OwnerId": "XXXXXXXXXXX", 
    "ReservationId": "XXXXXXXXXX", 
    "Groups": [], 
    "Instances": [
        {
            "Monitoring": {
                "State": "disabled"
            }, 
            "PublicDnsName": "", 
            "RootDeviceType": "ebs", 
            "State": {
                "Code": 0, 
                "Name": "pending"
            }, 
            "EbsOptimized": false, 
            "LaunchTime": "2016-12-06T11:48:25.000Z", 
            "PrivateIpAddress": "XXX.XXX.XXX.XXX", 
            "ProductCodes": [], 
            "VpcId": "vpc-XXXXXXXXXX", 
            "StateTransitionReason": "", 
            "InstanceId": "i-98abXXXXX", 
            "ImageId": "ami-0c11b26d", 
...

Below is the console after execution. (You can instantiate it with just one button! It's i-98abXXXXX) after.png

I tried Aws Lambda Dash Button

This time, I have created a normal function called hello world in advance. lambda.png It just outputs "Hello from Lambda".

Create dash-lambda.py.

dash-lambda.py



from scapy.all import *
def arp_display(pkt):
  if pkt[ARP].op == 1: #who-has (request)
    if pkt[ARP].psrc == '0.0.0.0': # ARP probe as your env
      if pkt[ARP].hwsrc == 'XX:XX:XX:XX:XX:XX': # MAC address as your env 
        print "Aws lambda button Pushed."
        os.system("aws lambda invoke --invocation-type RequestResponse --function-name helloworld --region ap-northeast-1 --log-type Tail --payload '{}' output.txt")
        #Just added here(The wording of the print on it is also changed a little)
        sys.exit()

print sniff(prn=arp_display, filter="arp", store=0, count=10)

Then execute.


$ sudo python dash-lambda.py 
WARNING: No route found for IPv6 destination :: (no default route?)
#Since it is output so far, press the Dash button
Aws lambda button Pushed.
{
    "LogResult": "XXXXXXXXXXXXXX", 
    "StatusCode": 200
}
$ cat output.txt 
"Hello from Lambda"$ 
#The output result is taken!

I was able to do it like that.

in conclusion

――I didn't come out even if I googled it, so I thought it was only now and did it with momentum ――However, if you google "amazon dash button (programming language)", you can find many articles from overseas, which is convenient. --If Amazon IoT Button is available in Japan in the first place ... [I tried disassembling the AWS IoT Button #reinvent | Developers.IO](http://dev.classmethod.jp/cloud/aws/decomposition-aws- iot-button /) ――Actually, I was thinking of doing it on windows at first, but it was the most annoying to put scapy, and when I noticed, I put ubuntu in the chromebook and did it on it ――I was a little impressed that you could create a server with the touch of a button, and could you sell it to an in-house app engineer at a good price? ――And when you play, the notification of the smartphone Interestingly w

スマフォのスクショ.png

――Since I finished using it, I disabled it and reset it. Amazon.co.jp Help: Disable Dash Button

that's all.

Recommended Posts

I made an Amazon Web Service Dash button
I made an Ansible-installer
I made an Xubuntu server.
I hacked the Amazon Dash Button and registered with Salesforce
I made an Anpanman painter discriminator
I made a dash docset for Holoviews
I made an online frequency analysis app
I made an alternative module for japandas.DataReader
I made a WEB application with Django
I made an extenum package that extends an enum
Obstacle (black) I made an automatic avoidance caterpillar.
"Amazon Dash Button" has landed in Japan, but I dared to make it myself
I made an action to automatically format python code
I made an IFTTT button that unlocks the entrance 2 lock sesame with 1 button (via AWS Lambda)