Send a text to yourself from AWS Lambda

Yes. Homing Pigeon (homingpigeon.dev) lets a Lambda function text your phone when a scheduled job fails or a CloudWatch alarm goes off, with your key in an environment variable and no layer to build. Your coding agent can add it to the function you already have.

What to tell your agent

Use Homing Pigeon to text me when this Lambda function fails.

Your agent asks for your number, you read back the six-digit code, and it does the rest.

How it works in code

Run pip install homingpigeondev -t . in your function's folder, so the package ships in the zip next to lambda_function.py. Then wrap the job, and replace run_job with your own code:

import homingpigeondev


def lambda_handler(event, context):
    try:
        run_job(event)
    except Exception as err:
        event_id = event.get("id") or context.aws_request_id
        homingpigeondev.send(
            f"{context.function_name} failed: {str(err)[:200]}",
            idempotency_key=f"failed-{event_id}",
        )
        raise

For an error alert, create a CloudWatch alarm on your function's Errors metric that notifies an SNS topic, then subscribe a second function to that topic. This one uses only the standard library, so you can paste it into the console editor with nothing to package:

import json, os, urllib.request


def lambda_handler(event, context):
    for record in event["Records"]:
        alarm = json.loads(record["Sns"]["Message"])
        body = {
            "message": f"{alarm['AlarmName']} is in {alarm['NewStateValue']}.",
            "idempotency_key": record["Sns"]["MessageId"],
        }
        req = urllib.request.Request(
            "https://homingpigeon.dev/v1/send",
            data=json.dumps(body).encode(),
            headers={
                "Authorization": f"Bearer {os.environ['HOMINGPIGEON_API_KEY']}",
                "Content-Type": "application/json",
            },
        )
        urllib.request.urlopen(req, timeout=10)

Good to know

  • Set HOMINGPIGEON_API_KEY under Configuration, Environment variables, in the Lambda console. After you verify your phone, npx -y homingpigeondev key prints the key. Both versions read it from there, so it stays out of your code.
  • To upload the first version, zip the folder's contents with zip -r ../function.zip . from inside it, then choose Upload from, .zip file, under Code. The package has no dependencies, so it needs no layer.
  • To run the job on a schedule, add an EventBridge trigger with a schedule expression such as rate(1 day) or cron(0 13 * * ? *). Times in these expressions are UTC.
  • EventBridge invokes the function asynchronously, and Lambda retries a failed run up to two times with the same event. The event ID in the idempotency key means you get one text, not three. A quiet phone means the job worked.
  • The try cannot catch a timeout, because Lambda stops the function. The Errors metric counts timeouts too, so the alarm catches what the try misses. The default timeout is 3 seconds, so raise it under Configuration, General configuration, to leave time for the text.
  • A function attached to a VPC reaches the internet only through a NAT gateway. Without one, the text cannot go out.
  • Messages are limited to 480 characters and go only to the US mobile number you verified. Keep them plain, with no links. Delivery is not guaranteed, so treat each text as a heads-up.

Get started

Add Homing Pigeon to Claude Code, then ask for what you want:

claude mcp add homingpigeondev -- npx -y homingpigeondev mcp

You get 50 free texts every month, on US mobile numbers. See more use cases.