Neat trick: Use AWS SNS to get a text message when a process completes

As software developers we sometimes end up doing really long-winded things such as migrating databases or re-compiling large projects. We often ‘fire-and-forget’, going off to do some other task while our process finishes.

Typically, we then repeatedly interrupt ourselves to check back on the task, or just completely forget about it until long after it’s complete.

Some enterprising developers use sendmail to send themselves an email when their process completes. It looks something like:

echo "super long build complete!" | sendmail -v you@yourdomain.com

But sendmail requires some non-trivial configuration to get working, and you may only be getting emails on the machine you’re working on anyway. Wouldn’t it be nice to get a reminder on your phone?

With AWS SNS, you can do just that, thanks to SNS’ remarkable ability to send messages over SMS. Here’s what you need:

  1. Access to an AWS account
  2. The AWS CLI
  3. IAM role that can perform sns:Publish
  4. A named profile configured to use your IAM role.

Once you have all that, sending a text message with SNS is as simple as:

aws --profile $YOUR_NAMED_PROFILE publish --phone-number $YOUR_PHONE_NUMBER --message "Task done! Yay!"

You can scriptify this:

lmk.sh:

#!/bin/bash
phone_number="$1"
aws --profile $YOUR_NAMED_PROFILE publish --phone-number $phone_number --message "Task done! Yay!"

And use:

echo "a super long build..." | ./lmk.sh $YOUR_PHONE_NUMBER

Easy!

You can now concentrate on whatever task you moved on to and know that when your build/migration/whatever is done you’ll get a nice little reminder on your phone.

Caveat: SMS through SNS is supported in a limited set of regions and countries. See the docs for a list.