使用 AWS Lambda 搭配 EventBridge (CloudWatch Event) 定時發送每日資料至 Telegram
-
基金資料, 每日更新時間約為 9:30 ~ 10:00 之間
EventBridge Schedule expression:
cron(0 2 ? * TUE-SAT *)
-
美股資料, 每日收盤時間為 04:00 (UTC+8), 夏令 05:00 (UTC+8)
EventBridge Schedule expression:
cron(30 21 ? * MON-FRI *)
要把 package 都包進 zip, 再上傳到 AWS Lambda
另外一個做法是把 package 包成 zip, 放到 layer 內, 如果是 python, 要在 zip 內新增一個 python 資料夾
參考以下連結的 Include library dependencies in a layer
Creating and sharing Lambda layers - AWS Lambda
pillow.zip
│ python/PIL
└ python/Pillow-5.3.0.dist-info
教學課程:在 Python 3.8 中建立 Lambda 函數 - AWS Lambda
Building a Telegram Bot with AWS API Gateway and AWS Lambda - DEV Community
url 為 API Gateway 的 URL
https://api.telegram.org/bot{token}/setWebhook?url=https://{restapi_id}.execute-api.{region}.amazonaws.com/{stage_name}/
會回傳
{"ok":true,"result":true,"description":"Webhook was set"}
在 Amazon API Gateway 中叫用 REST API - Amazon API Gateway
https://api.telegram.org/bot{token}/getWebhookInfo
getwebhookinfo - Telegram Bot API
可以用 @botfather, /setcommands
How to show options in telegram bot? - Stack Overflow
setmycommands - Telegram Bot API
Extensions – Your first Bot · python-telegram-bot/python-telegram-bot Wiki