Use node.js to connect to the Redis server running on AWS EC2. It works fine when connecting to the Redis server from outside, but if you run the server on an instance where Redis is running, the Redis connection log is the same, but you get an error when you try to inquiry and modify data.
const redis = require('redis');
require('dotenv').config();
const client = redis.createClient({
url: process.env.REDIS_URL
});
client.on('error', (err) => {
console.log('Redis error: ', err);
});
client.on('connect', () => {
console.log('connect success!');
});
client.on('ready', () => {
console.log('RedisClient is ready');
});
client.connect();
module.exports = client;
When running the server that uses this module on a personal PC, it works without any issues. However, when running the server on an EC2 instance where the Redis server is running, it connects without any problems, but when trying to use the module, a ‘NOAUTH Authentication required’ error occurs.
Why does the error occur only on the EC2 instance? And what are the possible solutions?
I Edited redis.conf.
bind 0.0.0.0, requirepass password and protected-mode yes.
and
redis url in EC2 is “redis://default:[email protected]:6379”