
Tricks using Cloud #3: Deploying a Serverless Telegram Bot with AWS
In this episode, we’ll learn how I combined AWS services to build a lightweight monitoring service that interacts directly with a Telegram bot without deploying any server o container.
When people first hear about serverless computing, they often imagine something abstract or overly complex. In reality, services like AWS Lambda and API Gateway make it possible to build real-world, production-ready applications without provisioning or maintaining any servers.
Why Serverless?
Serverless is not about “no servers.” It’s about abstracting infrastructure management. Instead of creating an EC2 instances, design network or creating containers, you can focus entirely on writing code that reacts to events:
- AWS Lambda lets you run code on demand, billed by the millisecond, using ARM or x86_64 architecture
- Amazon API Gateway exposes these functions securely over HTTPS
- Together, they create an event-driven model that scales seamlessly
For small, interactive services — like a chatbot or notification engine — this model is a perfect fit.
Building Blocks
Before diving into the example, let’s recap the components I used:
- Telegram Bot — the front-end interface where users interact
- AWS Lambda — stateless functions running the logic (commands, monitoring, notifications)
- Amazon API Gateway — the HTTPS bridge between Telegram and our Lambda functions
- Amazon S3 — lightweight persistence for configuration and monitoring state
- AWS Secrets Manager (optional) — securely manage tokens or credentials

Step 1 – Creating the Telegram Bot
Telegram provides a very straightforward APIs for creating bots. To do this you can use @BotFather Bot to create your bot.
Once you’ve obtained a bot token, the next step is to tell Telegram where to deliver incoming updates.
That’s where API Gateway enters the stage.
Step 2 – Connecting Telegram to Lambda via API Gateway
I set up an API Gateway endpoint (for example, /bot_webhook
) and linked it to our Lambda handler. API Gateway provide a public endpoint that we need to register our webhook together bot token:
curl -X POST "https://api.telegram.org/botYOUR_BOT_TOKEN/setWebhook?url=https://YOUR_ENDPOINT_API_GATEWAY"
Every time a user sends a message to the bot, Telegram pushes it to the API Gateway URL, that triggers the Lambda.
Telegram → API Gateway → Lambda → Response
This creates a fully serverless webhook without needing to run a dedicated server.
Step 3 – Command Handling in Lambda
Inside the Lambda, the Python code parses the incoming message and executes the right action.
Commands like /start
, /help
, or /status
are mapped to specific functions.
Although I’m not pasting full code here, the structure is fairly simple:
if message starts with "/start" → send welcome message
if message starts with "/help" → send usage instructions
if message starts with "/status" → return current monitoring info
else → treat as input for monitoring
Responses are sent back to Telegram using the standard Bot API.
Step 4 – Monitoring Logic
The real use case was about tracking availability of specific items.
Users send a link and a keyword (e.g. type, category, or product option), and Lambda stores this configuration in S3 as JSON.
A second Lambda, triggered periodically via Amazon EventBridge, checks all active monitoring entries:
- Reads the monitoring list from S3
- Queries the external source (with browser-like headers to simulate a normal request)
- If a match is found, it sends a Telegram notification
This makes the system event-driven and automated without manual checks.
Step 5 – Security and Access Control
Not everyone should be able to use the bot.
To solve this, I introduced a simple password mechanism. Users authenticate by sending a code, validated against a secure source (AWS Secrets Manager). This way, new users can be enabled or revoked dynamically without code changes.
Architecture Overview
Here’s the big picture:
+--------------------+
| Telegram Client |
+--------------------+
|
v
+--------------------+ +----------------+
| API Gateway | --> | Lambda (Bot) |
+--------------------+ +----------------+
|
v
+-----------------+
| Amazon S3 |
| (monitor state) |
+-----------------+
|
v
+-----------------+
| Lambda (Monitor)|
+-----------------+
|
v
+-------------------+
| Telegram API (out)|
+-------------------+
Benefits of Going Serverless
- Scalability — handles 1 user or 1,000 without changes
- Cost efficiency — pay only for actual execution time
- Security — no public servers, just API Gateway with controlled access
- Maintainability — adding features means updating a single Lambda
Next Steps
From here, the possibilities are endless:
- Add DynamoDB for more structured monitoring state
- Integrate with other channels (SNS, Slack, email)
- Build a front-end dashboard powered by API Gateway + Lambda
This small project demonstrates how far you can go with just AWS Lambda, API Gateway, and a few integrations. It’s a real-world, lightweight application that shows the power of serverless design — and how quickly you can turn an idea into a working service.