gRPC is not working as expected in lamda function

Viewed 686

I have grpc server and client implemented in nodejs. Server is running on 0.0.0.0:8080. Client can connect just fine when I test in local. But when I move client to aws-lambda function and invoke locally it does not work. Server does not get any request. Any idea what might be the problem?

I have tried changing ports and turning off firewall. Still no success.

Any help is appreciated.

Here is the server.js

const grpc = require('grpc');
const path = require('path');

const FILE_PATH = './schema.proto';
const PROTO_PATH = path.resolve(__dirname, FILE_PATH);
const protoLoader = require('@grpc/proto-loader');
const tourProcess = require('../../src/modules/tour/src/controllers/internal/v100');

const server = new grpc.Server();
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
  keepCase: true,
  longs: String,
  enums: String,
  arrays: true,
  oneofs: true
});


const pivoTourProto = grpc.loadPackageDefinition(packageDefinition).grpcPivoTour;
server.addService(pivoTourProto.pivoTourService.service, {
  getTours: tourProcess.getTours
});

server.bind('0.0.0.0:8080', grpc.ServerCredentials.createInsecure());
console.log('GRPC running at 127.0.0.1:8080');
module.exports = server;
client.js

var path = require('path');
const FILE_PATH = "./schema.proto";
const PROTO_PATH = path.resolve( __dirname, FILE_PATH );
const grpc = require("grpc");
const protoLoader = require("@grpc/proto-loader");

var packageDefinition = protoLoader.loadSync(PROTO_PATH, {
  keepCase: true,
  longs: String,
  enums: String,
  arrays: true
});

const pivoTourProto = grpc.loadPackageDefinition(packageDefinition).grpcPivoTour;
const client = new pivoTourProto.pivoTourService(
    '0.0.0.0:8080',
    grpc.credentials.createInsecure()
);

module.exports = client;
//LAMBDA HANDLER lambda.js


require('dotenv').config();
const client = require('./src/grpc/client');

module.exports.handler = async (event, context, callback) => {
    tourId = "1";
    const req = {"id": tourId};

    client.getTours(req, function(error, tour){
        if(error){
        console.log(error);
        }else{
        console.log(tour);
        }
    
    });

};

0 Answers
Related