A simple template to deploy a serverless telegram bot on AWS Lambda.
- python-telegram-bot: python wrapper for Telegram Bot API's.
- Zappa: framework to easy deploy and manage serverless AWS Lambda functions.
- Flask: python framework
Contacts: andreamazzoni78@gmail.com
In order to run your own bot you have to provide:
- AWS Account (https://aws.amazon.com)
- A Telegram bot token (https://core.telegram.org/bots#3-how-do-i-create-a-bot)
Put your AWS credentials and default region on ~/.aws/config
file:
[default]
aws_access_key_id=<access_key_id>
aws_secret_access_key=<secret_access_key>
region=<your default region> (es: eu-central-1, us-east-1...)
Clone this repo locally and setup dependencies:
git clone https://github.com/andreamazzoni/aws-lambda-echobot
cd aws-lambda-echobot
virtualenv ~/virtualenvs/aws-lambda-echobot-env
source ~/virtualenvs/aws-lambda-echobot-env/bin/activate
At the time I write Zappa it's not fully compatible with last pip version, so you have to downgrade to 9.0.3 and then install dependencies:
pip install pip==9.0.3
pip install -r requirements.txt
Provide your private bot token in config.py
file.
Initialize zappa with zappa init
command. You can keep all defaults. Check zappa_settings.json
.
Deploy your bot on AWS Lambda with this zappa command: zappa deploy dev
. Use endpoint that zappa give to you to properly set telegram webhook. For example fire this URL with your browser:
http://api.telegram.org/bot<your_bot_token>/setWebhook?url=<your_aws_api_endpoint>
Have fun!