I'm trying to connect to Elasticache redis instance from lambda. Lambda and Elasticache are on same vpc and Lambda's execution role has all the permission for elasticache. But still I'm getting ECONNREFUSED.
const redis = require("redis");
const AWS = require("aws-sdk");
const apig = new AWS.ApiGatewayManagementApi({
endpoint: process.env.ApiGatewayEndpoint,
});
exports.handler = async (event, context) => {
const redisClient = redis.createClient({
host: "botgo-cache.fhvwf2.ng.0001.aps1.cache.amazonaws.com",
port: "6379",
});
await redisClient.connect();
redisClient.on("connect", (err) => {
console.log("Redis Connected " + err);
});
redisClient.on("error", (err) => {
console.log("Redis Error " + err);
});
const TEST_KEY = "test_node";
await redisClient.json.set(TEST_KEY, ".", { node: 4303 });
const value = await redisClient.json.get(TEST_KEY, {
// JSON Path: .node = the element called 'node' at root level.
path: ".node",
});
console.log(`value of node: ${value}`);
};