const worker = async () => {
await mongoose.connect(MONGODB_CONNECTION_STRING);
const client = createClient({
url: REDIS_URI,
password: AWS_SECRET_KEY
});
console.log(client);
console.log('Startinggggggg');
await new Promise((resolve, reject) => {
client.once('ready', () => {
console.log('Connected to MemoryDB for Redis');
resolve("Done");
});
client.once('error', (err) => {
console.error('Error connecting to MemoryDB for Redis:', err);
reject(err);
});
setTimeout(() => {
console.error('Timed out connecting to MemoryDB for Redis');
reject('Timed out connecting to MemoryDB for Redis');
}, 10000);
});
//create http server
const server = http.createServer(app);
//create socket server
const io = new Server(server, {
cors: {
origin: "*",
methods: ["GET", "POST"],
credentials: false,
},
});
io.adapter(createAdapter(client.connect(), client.duplicate().connect()));
//handle socket.io
ioHandler(io);
const port = process.env.port;
server.listen(port, () =>
console.log(`worker ${cluster.worker?.id} listening on port ${port}`)
);
};
I am using memorydb provided by aws to replace redis-client for serverless communication between containers, locally the redis-client has helped, but in production i have to use memorydb. First of all i have used the my secret key as the password to connect to it. I think the code is correct, but i am getting timeoutconnection error everytime.
what can be the problem? i have set the inbound and outbound rules of security group to allow all traffic.
I got the issue now.
If one need to access MemoryDB resources from outside of AWS for test or development purposes, you can do so by setting up a VPN connection using AWS Client VPN. This will provide encrypted traffic, limited access to specific subnets or nodes, and the ability to restrict access to approved users or authentication keys. Additionally, it makes it easy to revoke access and audit connections. However, it's important to note that external access to MemoryDB is discouraged due to security concerns and the potential latency of Internet traffic.