{"id":26717867,"url":"https://github.com/vhuynen/telegram-lambda-aws-python","last_synced_at":"2026-05-05T21:38:13.341Z","repository":{"id":197595253,"uuid":"346000716","full_name":"vhuynen/Telegram-Lambda-AWS-Python","owner":"vhuynen","description":"This Lambda function allows to send an message through Telegram Bot API when it is triggered by Amazon SNS (Simple Notification Service).","archived":false,"fork":false,"pushed_at":"2022-09-21T19:33:26.000Z","size":978,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T16:40:32.015Z","etag":null,"topics":["aws","aws-lambda","telegram-api"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vhuynen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-03-09T12:36:38.000Z","updated_at":"2023-08-25T18:33:24.000Z","dependencies_parsed_at":"2023-10-01T15:42:13.299Z","dependency_job_id":null,"html_url":"https://github.com/vhuynen/Telegram-Lambda-AWS-Python","commit_stats":null,"previous_names":["vhuynen/telegram-lambda-aws-python"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vhuynen/Telegram-Lambda-AWS-Python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vhuynen%2FTelegram-Lambda-AWS-Python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vhuynen%2FTelegram-Lambda-AWS-Python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vhuynen%2FTelegram-Lambda-AWS-Python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vhuynen%2FTelegram-Lambda-AWS-Python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vhuynen","download_url":"https://codeload.github.com/vhuynen/Telegram-Lambda-AWS-Python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vhuynen%2FTelegram-Lambda-AWS-Python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32669433,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-05T11:29:49.557Z","status":"ssl_error","status_checked_at":"2026-05-05T11:29:48.587Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-lambda","telegram-api"],"created_at":"2025-03-27T16:31:00.861Z","updated_at":"2026-05-05T21:38:13.313Z","avatar_url":"https://github.com/vhuynen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Send Telegram Bot with Python and AWS Lambda \n\nThis Lambda function allow to send an message through Telegram Bot API when it is triggered by Amazon SNS (Simple Notification Service).\n\n# Deprecated version\n\nThis function use the vendored version of **requests** library from **Botocore** and Python 3.7 runtime.  \n\n```python\nimport json\nimport os\nfrom botocore.vendored import requests\n\nTELEGRAM_TOKEN =os.environ.get(\"TELEGRAM_TOKEN\")\nTELEGRAM_CHAT_ID=os.environ.get(\"TELEGRAM_CHAT_ID\")\n\ndef lambda_handler(event, context):\n    bot_request = 'https://api.telegram.org/' + TELEGRAM_TOKEN + '/sendMessage?chat_id=' + TELEGRAM_CHAT_ID + '\u0026text=' + event['Records'][0]['Sns']['Message'] \n    print(event)\n    print(bot_request)\n    response = requests.get(bot_request) \n    return {\n       'statusCode': response.status_code,\n       'msg': json.dumps('Message sent with success!'),\n       'body': json.dumps(response.json())\n   }\n```\n\nWhen you execute this function you have an warning log that the HTTP Client from **Botocore** is deprecated and that it will be removed from lambda after **2021/03/31**.\n\n```\n/var/runtime/botocore/vendored/requests/api.py:72: DeprecationWarning: You are using the get() function from 'botocore.vendored.requests'.  This dependency was removed from Botocore and will be removed from Lambda after 2021/03/31. https://aws.amazon.com/blogs/developer/removing-the-vendored-version-of-requests-from-botocore/. Install the requests package, 'import requests' directly, and use the requests.get() function instead\nDeprecationWarning\n```\n\nFor more information, you can read this paper about this topic : https://aws.amazon.com/fr/blogs/developer/removing-the-vendored-version-of-requests-from-botocore/\n\n# Stable version\n\nThis lambda function use the strong **requests** library **urllib3** and Python 3.8 runtime.\n\n```python\nimport json\nimport os\nimport requests\n\nTELEGRAM_TOKEN =os.environ.get(\"TELEGRAM_TOKEN\")\nTELEGRAM_CHAT_ID=os.environ.get(\"TELEGRAM_CHAT_ID\")\n\ndef lambda_handler(event, context):\n    bot_request = 'https://api.telegram.org/' + TELEGRAM_TOKEN + '/sendMessage?chat_id=' + TELEGRAM_CHAT_ID + '\u0026text=' + event['Records'][0]['Sns']['Message']  \n    print(event)\n    print(bot_request)\n    response = requests.get(bot_request) \n    return {\n        'statusCode': response.status_code,\n      'msg': json.dumps('Message sent with success!'),\n       'body': json.dumps(response.json())\n  }\n```\n\nTo execute this function you must import yourself the requests library into your package and then use the console to upload and deploy the package.\n\n- Import the library **requests** into a work directory on your file system :\n  - `sudo pip install requests -t .`\n\n- Create `lambda_function.py`  into your work directory\n\n- Copy the content of `lambda_function.py` from lambda console\n\n- Paste it in your `lambda_function.py` from your work directory\n\n- Zip the content of your work directory, which is your deployment package (Zip the directory content, not the directory)\n- Go to the Lambda console, select upload zip file and upload your deployment package\n- Deploy your code and execute the function\n\nNow, your lambda function should work without warning.\n\n# SNS Message structure\n\n```json\n{\n  \"Records\": [\n    {\n      \"EventSource\": \"aws:sns\",\n      \"EventVersion\": \"1.0\",\n      \"EventSubscriptionArn\": \"arn:aws:sns:us-west-2:xxxxxxx:IoTMailboxPLPSNSTopic:8c9b83d1-120e-4eaf-b125-825ed7f0e657\",\n      \"Sns\": {\n        \"Type\": \"Notification\",\n        \"MessageId\": \"73eb288c-5274-5e90-80ea-704d1f09b104\",\n        \"TopicArn\": \"arn:aws:sns:us-west-2:xxxxxxx:IoTMailboxPLPSNSTopic\",\n        \"Subject\": \"None\",\n        \"Message\": \"HelloWorld from SNS ! Message sent by AWS Lambda\",\n        \"Timestamp\": \"2021-03-09T10:17:33.245Z\",\n        \"SignatureVersion\": \"1\",\n        \"Signature\": \"\",\n        \"SigningCertUrl\": \"\",\n        \"UnsubscribeUrl\": \"\",\n        \"MessageAttributes\": {}\n      }\n    }\n  ]\n} \n```\n\n# Other snippet\n\nIn the same mindset, here a Twilio Lambda function to send SMS by **API Key** (client_id, client_secret) within **Basic Auth** header : https://gist.github.com/vhuynen/0681e0ca15c8142860961d3072eb616b\n\n\u003e API Keys are revokable credentials for the Twilio API. You can use API Keys to authenticate to the REST API using basic auth. And, you can use API Keys to sign Access Tokens, which are used by Twilio's Real-Time Communications SDKs. Access Tokens are short-lived credentials that can be distributed safely to client-side applications\n\nIn this snippet, Basic Auth is used and not the `Client Credentials Flow` from OAuth 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvhuynen%2Ftelegram-lambda-aws-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvhuynen%2Ftelegram-lambda-aws-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvhuynen%2Ftelegram-lambda-aws-python/lists"}