简体   繁体   中英

Lambda Elasticache redis connection refused

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}`);
};

您是否已将安全组添加到 Elasticache Redis 集群以允许传入流量到端口 6379?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM