In this post, I’ll share some code I use to check if I left an AWS EMR cluster running by lighting a red (off) or green (on) LED hooked up to an Arduino Uno. This sounds silly but it helps me remember to terminate my clusters before I leave work. Besides, what else am I going to do with a spare Arduino? :)
For this project I used an Arduino Uno, breadboard, 2x 220Ω resistors (red, red, brown, gold), a red LED, a green LED, and wire attached to ground, and 2 wires connected to digital pins (12 and 13).
I added the following code and flashed it to the Arduino Uno. It initializes the LED pins, reads from the serial connection, and sets the LEDs to on/off based on the bytes received from the USB connection.
I then added a Python script that uses boto3 (AWS SDK for Python) to check if a cluster is running that matches my name or tags. It then writes 1 or 0 to the (USB) serial connection based on the response and loops with a delay.
I turned on the Arduino Uno and executed python emr_status.py from my Mac to start the process. If I have an EMR cluster running, it lights the green LED. Else, the red LED is lit. Super helpful.