Connecting to elastiCache cluster with node.js
0
I am struggling to find node examples in connecting to my Elasticache cluster via node.js lambda using node-redis.
const { createCluster }= require('redis');
const redisClient = require('redis');
function createRedisClient() {
const client = createCluster({
rootNodes: [
{
host: process.env.redis_endpoint // This is the configuration endpoint given for the cluster plus port
}
]
});
return client;
}
I get an invalid protocol when I try to connect. I have tried adding 3 of the shard endpoints to the above code with the same result. I have tried just creating a redis client( rather than cluster) and get the same results. How is this done?
asked a month ago44 views
1 Answers
1
Hello,
as per node-redis source code , the error is thrown when ParseURL()
finds an invalid configuration:
if (protocol === 'rediss:') {
(parsed.socket as RedisTlsSocketOptions).tls = true;
} else if (protocol !== 'redis:') {
throw new TypeError('Invalid protocol');
}
I could not find "host" as a valid parameter for CreateCluster().rootNodes configuration.
You probably want to replace host
by url
and make sure that process.env.redis_endpoint
expands to a valid URL like:
redis[s]://[[username][:password]@][host][:port][/db-number]
Example:
- no in-transit encryption
const client = createCluster({
rootNodes: [
{
url: 'redis://Elasticache_Cluster_Endpoint_here:6379'
}
]
});
- in-transit encryption without authentication:
const client = createCluster({
rootNodes: [
{
url: 'rediss://Elasticache_Cluster_Endpoint_here:6379'
}
]
});
- in-transit encryption and RBAC/ACL authentication:
const client = createCluster({
rootNodes: [
{
url: 'rediss://user_name:password@Elasticache_Cluster_Endpoint_here:6379'
}
]
});
Relevant questions
ElastiCache multi-AZ setup with no replica
Accepted AnswerElasticache for Redis cluster service update got stuck
asked 3 months agoConnecting to elastiCache cluster with node.js
asked a month agoUnable to connect to redis cluster with node client, what am I doing wrong?
asked 5 months agoSeeding of a Elasticache cluster in another account in another region
asked 8 days agoLightsail container - connect to ElastiCache
asked 3 months agoCombatibility with redis api for testing mockups
asked a year agoIssues connecting to ElastiCache Memcached
asked 2 years agoElastiCache for Redis load distribution
asked 4 months agoAdding new shards didn't increase the total available memory
asked 2 years ago