Skip to content

A serverless Python AWS Lambda that checks Indian Railway PNR status via ConfirmTkt API and sends SMS/email alerts using SNS. Automates waitlist→confirmation tracking with EventBridge Scheduler. Perfect for real-time PNR notifications, railway status alerts, and travel updates.

Notifications You must be signed in to change notification settings

BitanSarkar/IRCTC-pnr-status-notifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚆 IRCTC-pnr-status-notifier

IRCTC PNR Status Notifier is a serverless AWS Lambda (Python 3.11) project that automatically checks your Indian Railway PNR status via the ConfirmTkt API and sends real-time SMS/Email alerts through AWS SNS.
It is designed to run on a schedule using Amazon EventBridge Scheduler, so you never have to manually refresh IRCTC or ConfirmTkt pages again.


🔹 Features

  • Real-time PNR Tracking – fetches live Indian Railway PNR status using ConfirmTkt API
  • Instant Alerts – sends notifications via AWS SNS (SMS & Email supported)
  • Serverless & Cost-Effective – built with AWS Lambda (Python 3.11)
  • Customizable Scheduling – integrate with EventBridge Scheduler for periodic checks
  • Minimal Setup – repo includes Lambda function code & IAM policy only
  • User-Managed Infra – you create the SNS Topic & EventBridge rules as per your needs

⚡ Why use this?

Built as a 1-hour mini hack, this notifier saves you from the repetitive hassle of checking your railway booking status. Simply deploy, schedule, and receive automated updates — no apps, no ads, just pure serverless automation.

Perfect for travelers, developers, and hobbyists who want hands-free IRCTC PNR monitoring.


🏗️ Architecture

The following diagram shows how the IRCTC PNR Status Notifier works:

IRCTC Notifier Architecture

Flow explanation:

  1. EventBridge Scheduler runs on a cron/rate expression (e.g., hourly).
  2. Scheduler invokes Lambda with an optional JSON input (e.g., {"PNR":"4224374267"}).
  3. Lambda calls the ConfirmTkt API, parses the passenger statuses, and compares against the previous run stored in SSM Parameter Store.
  4. If there is a change (e.g., WL → CNF), Lambda formats a message and publishes it to SNS Topic.
  5. SNS delivers the alert to your phone (SMS) or email inbox.

📂 What this repo includes

  • index.py — Lambda function (urllib-only, Python 3.11)
  • infra/iam-lambda-policy.json — IAM permissions for the Lambda role

Note: This repo does not create EventBridge Scheduler or SNS for you. You create them in your own AWS account.


⚙️ Setup Guide (Step by Step)

1) Create the Lambda IAM Role

  • In AWS Console → IAM → Roles → Create role.
  • Trusted entity: Lambda.
  • Attach CloudWatchLogsFullAccess (or equivalent minimal logging).
  • Attach an inline policy using infra/iam-lambda-policy.json.
    • Replace ACCOUNT_ID and region in ARNs with your values.

2) Create an SNS Topic

  • Console → SNS → Topics → Create topic.
  • Example name: pnr-updates.
  • Add subscriptions:
    • Email (free) → confirm via email.
    • SMS (India ~₹1–1.5/msg).
  • Copy the Topic ARN (e.g., arn:aws:sns:REGION:123456789012:pnr-updates).

3) Deploy the Lambda Function

  • Zip and deploy:
zip lambda.zip index.py
aws lambda create-function   --function-name pnr-watch   --runtime python3.11   --role arn:aws:iam::ACCOUNT_ID:role/pnr-watch-role   --handler index.handler   --timeout 30   --zip-file fileb://lambda.zip   --region REGION
  • Update environment variables:
aws lambda update-function-configuration   --function-name pnr-watch   --environment "Variables={
    PNR=4224374267,
    SNS_TOPIC_ARN=arn:aws:sns:REGION:ACCOUNT_ID:pnr-updates,
    SSM_PARAM_NAME=/pnr/4224374267/last_statuses,
    HTTP_TIMEOUT=10,
    TEST_SMS=1
  }"
  • Invoke manually once:
aws lambda invoke --function-name pnr-watch --payload '{}' out.json

You should receive a test snapshot SMS/Email. After verification, set TEST_SMS=0.

4) Create an EventBridge Scheduler

  • Console → EventBridge SchedulerCreate schedule. a- Expression: cron(0 * * * ? *) → every hour, at minute 0. (Timezone: Asia/Kolkata recommended.)
  • Target: Lambda function (pnr-watch).
  • Input (optional if PNR is set via env):
{"PNR": "4224374267"}

(Optional) Add a second schedule near the Date of Journey (DOJ) with higher frequency (rate(10 minutes)) using start/end dates.


🌐 Environment Variables

Variable Required Default Description
SNS_TOPIC_ARN ✅ Yes SNS Topic ARN for alerts
PNR ✅ Yes Default PNR (if not provided by Scheduler input)
SSM_PARAM_NAME ❌ No /pnr/<PNR>/last_statuses Where last statuses are persisted
HTTP_TIMEOUT ❌ No 10 HTTP timeout in seconds
TEST_SMS ❌ No 0 If 1, always send snapshot on every run
LOG_PAYLOAD_PREVIEW ❌ No 0 or 400 Log body snippet bytes (0 to disable)

📲 Example SMS Output

🚆 PNR 4224374267
Train: DURONTO EXPRESS (12246)
DOJ: 26-10-2025 | Class: 1A

P1 ➜ CNF
P2 ➜ GNWL 1 (91% Chance)

Chart: Not Prepared

💰 Cost

  • Lambda: ~4,300 invocations/month → Free tier (1M free).
  • EventBridge Scheduler: ~4,300 schedules/month → Free tier (100k free).
  • SNS Email: Free.
  • SNS SMS (India): ~₹1–1.5 per alert.
    Since you only care about status flips, total cost ≈ ₹2–3 per journey.

📌 Notes

  • This project is intended for personal use.
  • ConfirmTkt API is used for fetching PNR info.
  • Always respect site ToS.
  • You can monitor multiple PNRs by creating multiple schedules with different Input payloads.

About

A serverless Python AWS Lambda that checks Indian Railway PNR status via ConfirmTkt API and sends SMS/email alerts using SNS. Automates waitlist→confirmation tracking with EventBridge Scheduler. Perfect for real-time PNR notifications, railway status alerts, and travel updates.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages