Tutorials July 2026

How to Run a Python Script on a Schedule in the Cloud (2026)

Stop leaving your laptop running. This is the definitive guide to scheduling Python scripts in the cloud — from cron syntax to choosing the right hosting platform.

L
LiteLambda Team
9 min read

You've written a Python script that works on your machine. Now you want it to run automatically — every hour, every morning, every Monday. And you don't want to leave your laptop on to do it.

This guide covers everything: cron syntax, cloud scheduling options, and a step-by-step tutorial to go from a local script to a running cloud job in under 10 minutes.

Understanding Cron Expressions

Before picking a platform, you need to understand cron syntax — the standard way to define schedules.

A cron expression has 5 fields:

┌─────── Minute (0–59)
│ ┌───── Hour (0–23)
│ │ ┌─── Day of month (1–31)
│ │ │ ┌─ Month (1–12)
│ │ │ │ ┌ Day of week (0–7, 0 and 7 = Sunday)
│ │ │ │ │
* * * * *

Common schedules:

Expression Meaning
* * * * * Every minute
*/15 * * * * Every 15 minutes
0 * * * * Every hour (at :00)
0 9 * * * Every day at 9:00 AM UTC
0 9 * * 1-5 Weekdays at 9 AM UTC
0 9 * * 1 Every Monday at 9 AM UTC
0 0 1 * * First day of every month
0 9,17 * * * Twice daily (9 AM and 5 PM)

Need help building a cron expression? Use the LiteLambda Cron Expression Tester.

Preparing Your Script for Cloud Deployment

A script that runs locally needs a few adjustments to run reliably in the cloud.

1. Use environment variables for secrets

Never hardcode API keys, passwords, or tokens. Instead:

import os

# ❌ Wrong
API_KEY = "sk-abc123..."

# ✅ Right
API_KEY = os.environ["OPENAI_API_KEY"]

On LiteLambda, you set these in the Env Vars section of your cron job. They're encrypted at rest.

2. Use a handler function

Cloud platforms need an entry point. LiteLambda uses the handler(event, context) pattern (similar to AWS Lambda):

import requests
import os
from datetime import datetime

def handler(event, context):
    """
    This is your cron job entry point.
    'event' contains metadata about the trigger.
    'context' contains execution info.
    Return a dict — it gets logged as your execution result.
    """

    # Your actual logic here
    result = do_something()

    return {
        "status": "success",
        "result": result,
        "ran_at": datetime.utcnow().isoformat()
    }

def do_something():
    # Your script logic
    pass

3. Handle errors explicitly

Unhandled exceptions will crash your job silently on most platforms. Catch expected errors:

def handler(event, context):
    try:
        result = fetch_data()
        return {"status": "success", "data": result}
    except requests.Timeout:
        return {"status": "error", "reason": "API timeout"}
    except Exception as e:
        # LiteLambda will mark this run as failed and send an alert
        raise

4. List your dependencies

Instead of a full requirements.txt, list only what you import:

requests
pandas
openai
playwright

Most cloud cron platforms handle installation automatically from this list.

Cloud Scheduling Options in 2026

The fastest path from script to scheduled cloud job. Upload your code, set a schedule, and it runs. No infrastructure to manage.

Standout features:
- Built-in AI assistant: describe your task in English → get working Python code
- Playwright headless browser support (most platforms can't do this)
- Execution log for every single run
- Email + Telegram failure alerts
- Pay per execution — not for idle time

Pricing: Free for up to 1,000 credits/month. Starter at $4.99/month for serious use.

Option 2: AWS EventBridge + Lambda

The enterprise option. Powerful, infinitely scalable, but requires significant setup:

  • Creating a Lambda function
  • Packaging dependencies (Lambda Layers or container images)
  • Setting up EventBridge rules
  • Configuring IAM permissions
  • CloudWatch for logs and alerts

Realistic setup time: 2–4 hours for someone familiar with AWS.
Cost: Nearly free at low scale, but the complexity cost is real.

Option 3: Railway Cron Jobs

Good if you're already on Railway. Set up a worker service and a cron schedule. Straightforward, and Railway's UI is developer-friendly.

Cost: Hobby plan has free credits, paid plans from $5/month.

Option 4: Google Cloud Scheduler + Cloud Run

Similar to the AWS approach — Google Cloud Scheduler triggers an HTTP endpoint (Cloud Run function) on a schedule. Solid enterprise option, similar complexity to AWS.

Option 5: Running on a VPS (Crontab)

The old-school approach: rent a $5/month VPS (DigitalOcean, Hetzner, Linode), install Python, and use the system crontab.

# On your VPS, edit crontab
crontab -e

# Add:
0 9 * * * /usr/bin/python3 /home/user/scripts/daily_report.py

Pros: Full control, cheapest per execution at high volume
Cons: You manage the server (OS updates, disk space, uptime monitoring), no built-in alerting, no web UI


Full Tutorial: Deploy a Python Script to Run Daily

Let's deploy a real example: a script that fetches your GitHub repository's star count daily and logs it.

Step 1: Write the script

import requests
import os
from datetime import datetime

def handler(event, context):
    """
    Fetch GitHub star count for a repo and log it.
    """
    github_token = os.environ.get("GITHUB_TOKEN")  # Optional, for higher rate limits
    repo = os.environ.get("GITHUB_REPO", "python/cpython")

    headers = {}
    if github_token:
        headers["Authorization"] = f"token {github_token}"

    response = requests.get(
        f"https://api.github.com/repos/{repo}",
        headers=headers,
        timeout=10
    )
    response.raise_for_status()

    data = response.json()
    stars = data["stargazers_count"]
    forks = data["forks_count"]

    print(f"[{datetime.utcnow().isoformat()}] {repo}: ⭐ {stars:,} stars, 🍴 {forks:,} forks")

    return {
        "repo": repo,
        "stars": stars,
        "forks": forks,
        "open_issues": data["open_issues_count"]
    }

Step 2: Deploy on LiteLambda

  1. Go to litelambda.in/crons/new/
  2. Give your job a name: "GitHub Stars Tracker"
  3. Paste the code above into the editor
  4. Add package: requests
  5. Set schedule: 0 9 * * * (daily at 9 AM UTC)
  6. Click Save

Step 3: Test immediately

Click Run Manually — you'll see the script execute in real time in the terminal output panel. The return value is logged as your execution result.

Step 4: Set environment variables (if needed)

In the Env Vars section, add:
- GITHUB_REPO = your-org/your-repo
- GITHUB_TOKEN = ghp_your_token (optional)

Step 5: Activate

Your job is now live. It will run every day at 9 AM UTC. If it fails, you'll get an email alert automatically.


Scaling Up: Running Multiple Scripts

Once you have one cron job working, adding more follows the same pattern. Common setups:

Script Schedule Example
Daily price alert 0 7 * * * Crypto/stock prices via API
Hourly data sync 0 * * * * Pull from external API, write to database
Weekly report 0 8 * * 1 Monday morning Slack/email digest
Uptime check */5 * * * * Ping your service, alert if down
Monthly cleanup 0 0 1 * * Archive old records, clean temp files

Each job is independent — separate code, separate logs, separate failure tracking.

Common Errors and How to Fix Them

ModuleNotFoundError: No module named 'xyz'
→ Add xyz to your packages list.

KeyError: 'API_KEY'
→ You're reading an env var that isn't set. Add it in the Env Vars section.

TimeoutError
→ Your script is taking too long. Either optimize it or upgrade to a plan with a higher timeout.

Script runs but returns nothing useful
→ Make sure your handler function returns a dict with meaningful keys. This becomes your execution result log.


Ready to schedule your Python script? Start on LiteLambda — free tier included →

Skip the infrastructure setup.

Run this exact code in our secure, isolated Docker sandbox. It takes 10 seconds to deploy.

Deploy this script in 60s →

No DevOps required.