Click here to Skip to main content
15,918,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wrote a telegram bot with aws lambda. I have an Api gateway endpoint which runs the event and triggers the lambda function.

Now the problem is that I can't get the "body" because it always returns the same error.

This is the request I can get printed, is there any way to get the data in body and work on that data?

    {'version': '2.0', 'routeKey': 'ANY /myTelegramBot', 'rawPath': '/V1/myTelegramBot', 'rawQueryString': '', 'headers': {'accept-encoding': 'gzip, deflate', 'content-length': '331', 'content-type': 'application/json', 'host': '', 'x-amzn-trace-id': 'Root=1-62a1ea06-2d8ea4b553aasddczxc7209e7', 'x-forwarded-for': '', 'x-forwarded-port': '443', 'x-forwarded-proto': 'https' 
        }, 'requestContext': {'accountId': '374177185789', 'apiId': 'awefsdfka3al', 'domainName': '', 'domainPrefix': 'av3p3ka3al', 'http': {'method': 'POST', 'path': '/V1/myTelegramBot', 'protocol': 'HTTP/1.1', 'sourceIp': '', 'userAgent': '' 
            }, 'requestId': 'TdGA-jhertEMkA=', 'routeKey': 'ANY /myTelegramBot', 'stage': 'V1', 'time': '09/Jun/2022: 12: 39: 34 +0000', 'timeEpoch': 1654778374039 
        }, 'body': '{ 
            "update_id": 1234356,\n"message": { 
                "message_id": 226, 
                "from": { 
                    "id": 456875213, 
                    "is_bot": false, 
                    "first_name": "gggggggg", 
                    "last_name": "Di gggg", 
                    "username": "gggggg", 
                    "language_code": "it" 
                "chat": { 
                    "id": ggggg, 
                    "first_name": "ggggggg", 
                    "last_name": "Di ggggg", 
                    "username": "ggggggg", 
                    "type": "private" 
                "date": 123123123, 
                "text": "HELLOMESSAGE" 
        }', 'isBase64Encoded': False 

My Aws lambda:

    CHAT_ID = 'xxxxxxxx' 
    TOKEN = 'xxxxx:AAEc_dP-xxxx' 
    WBH_URL = '' 
    def lambda_handler(event, context): 
        json_str = json.dumps(event) 
        resp = json.loads(json_str) 
        ####ERROR HERE: 
        chat_id_message = resp['Body']['message']['chat']['id'] 
        bot = telebot.TeleBot(TOKEN) 
        bot.send_message(CHAT_ID, "CIAOXXdalBOT" + str(resp)) 

Error: The Lambda function returned the following error: 'Body'. Check your Lambda function code and try again.

What I have tried:

I really tried everything, even formatting my answer with string analysis, but I think it is much easier than you think. I don't understand why the response is so bad

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900