AWS SQS – receive_message

When using the “receive_message” Python Boto function to pull message(s) from a SQS queue, you will always get a response back when the command completes.  However, how do you determine if the response you got back actually contains a valid message?

Quick trick:

response = sqs.receive_message
if 'Messages' in response:
    print("Message on the queue to process")
    print("No messages on the queue to process")

Thats about it!!


Blink(1) USB Light

I just got my Blink(1) in the mail today.  Its a cool indicator light that hooks into your USB port.


There is a ton of potential with this device.  You can utilize the Blink1Control2 application to setup event polling triggers or just play around with the colors. (e.g. Show red color when a specific email is received)

Or you can enable your device to listen on a specific port, which would allow you to update the device remotely via a curl command. (e.g. Jenkin job failure)  You can find the URL summary here.

Another option to using the light is to integrate it into a program, which would allow for more customizations.  Pretty easy to do with Python.  The Blink Python lib can be found here.

Python – Tesseract – OCR – IMAGE

You can do some pretty cool things with tesseract-ocr.  Using PyOCR, which is a wrapper for Tesseract, you can generate text from an image using Tesseract.

Example Image:


Example Output:


Example Code:

from wand.image import Image
from PIL import Image as PI
import pyocr
import io
import sys

tool = pyocr.get_available_tools()[0]
lang = tool.get_available_languages()[1]
txt_list = tool.image_to_string('/home/build/aws.jpg'),

outputFile = open('output.txt', 'w')
for item in txt_list:
 outputFile.write("%s" % item)

Another use case I was working on today was rendering the text in a PDF file using Tesseract.  I was converting the PDF to an image file first, then performing the above actions to read the text from the new image.

Here are a couple valuable resources I used to complete this little test.

  • Installing Tesseract on a RHEL system – (link)
  • Installing PyOCR and other image conversion tools – (link)

Getting all the prerequisites installed was by far the hardest part on this effort.

AWS Lambda and S3

Below are a couple of problems I ran into when writing a Python 2.7 Lambda function that created a file and then uploaded it to S3. (s3.upload_file)

  1. The file I was creating and writing to in the function was empty in S3 after the upload.
    • Turns out I needed the “( )” braces on the Python “close” command.  Silly issue, but took my like 20 minutes to figure out….
  2. In your Lambda function, you need to create your files under /tmp, which is your functions ephemeral storage.
    • fileName = ‘/tmp/’ + name


Cygwin and PIP Package Missing

I installed Cygwin today and forgot to install the PIP package for Python 2.7.


Looking online, I found that you could install the PIP package by re-running the Cygwin installation .exe.  However, re-running the .exe took a LOT longer than I expected.

It is 100% faster downloading and executing from the following location:

Execute “python -m pip –version” to verify your version!