Telegram node.js AWS Lambda 502 error


I have succeded with my first node app on Lambda using serverless. It works great when I open it from http endpoint after executing serverless deploy -v!

My target is to get my node.js telegram bot running on lambda. When I insert bot logic into export.module.hello , deploy in console, set telegram webhook, get no response after run /start command in my bot and then check same http endpoint webhook by opening - what I get is “Wrong response from the webhook: 502 Bad Gateway”

this is my handler.js code:

'use strict';

module.exports.hello = async (context, cb) => {
  const TelegramBot = require('node-telegram-bot-api');

  const token = "token";
  const bot = new TelegramBot(token);
  const chatId =;

  const out = bot.sendMessage(chatId, 'Hello World!');
  return cb(null, out);

and this is serverless.yml (functions part of it)

    handler: handler.hello
      - http: POST hello

I am comfortably running node.js code for telegram from a localhost, but seems cannot wrap this code inside lambda function… Otherwise what can be a problem causing 502 error, when I check getWebhookinfo?
Any advice will be much appreciated!



Hi, if I’m not mistaken bot.sendMessage returns a promise, you use an async function, so I think you don’t need to use cb + you need to add await + return a correct message.

  const TelegramBot = require('node-telegram-bot-api');

  const { TOKEN } = process.env;
  const bot = new TelegramBot(TOKEN); 

module.exports.hello = async (event) => {
  const chatId =;
  const result = await bot.sendMessage(chatId, 'Hello World!');

  return { statusCode: 200, body : JSON.stringify(result) };

p.s. have you tried to call this url using postman or something similar?