How do I keep my RabbitMQ worker functions active as Lambda functions?

These worker functions are RabbitMQ consumers that process incoming requests and reply with responses.

I’m looking for guidance on how to keep these worker functions always active after deploying the Lambda function. What configurations or practices can help achieve this?

// app.js
import e from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';
import morgan from 'morgan';
import 'dotenv/config.js';
import mongoose from 'mongoose';
import SwaggerRouter from './swagger.js';
import logger from './logger.js';
import StartUpRouter from './routes/user_founder.js'
import VCRouter from './routes/user_vc.js';
import SuperAdminRouter from './routes/superadmin.js';
import { handleVCListRequest, startTokenValidationWorker, startUserValidationWorker, startVCDataWorker } from './workers/messageQueueWorker.js';
import { startWorker } from './services/rabbitMQService.js';
import { processMessage } from './workers/emailWorker.js';

const app = e();

// ...other routes and middleware...

mongoose.connect(process.env.MONGO_URL, { useUnifiedTopology: true, useNewUrlParser: true })
.then(() => {
  app.listen(process.env.PORT || 4001);{listening: `Server is Processing on ${process.env.PORT}.`});{success: "Connected to AuthenticationService Database."});
  console.log({listening: `Server is Processing on ${process.env.PORT}.`});
  console.log({success: "Connected to Database."});

  startWorker(processMessage).catch((error) => {
    console.error('Error while sending email:', error.message);

  startTokenValidationWorker().catch((error) => {
    logger.error('Error starting token validation worker:', error.message);
    console.error('Error starting token validation worker:', error.message);

  // ...other worker functions...

  handleVCListRequest().catch((error) => {
    logger.error('Error starting vc list worker:', error.message)
    console.error('Error starting vc list worker:', error.message);
.catch((err) => {
  logger.error({error: err.message});
  console.error({error: err});

export default app;

// lambda.js
import ServerlessHttp from "serverless-http";
import app from "./app.js";

export const handler = ServerlessHttp(app);

>Solution :

AWS Lambda is not the right service here, as a serverless compute service.

While you can keep a Lambda function warm, the nature and purpose of serverless architectures is to not keep services running 24/7.

RabbitMQ consumers, that should always be listening for messages, should be running on a service like ECS, EC2 etc. that use servers & can be available 24/7.

Leave a Reply