
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
Easy-to-understand commentary. -> Amazon Dash Button super fast commentary --Qiita
$ 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
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.
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)
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)

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)

This time, I have created a normal function called hello world in advance.
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.
――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

――Since I finished using it, I disabled it and reset it. Amazon.co.jp Help: Disable Dash Button
that's all.
Recommended Posts