将 ElastiCache 连接到 Elastic Beanstalk 实例

Connect ElastiCache to Elastic Beanstalk Instance

我一直在阅读有关在我的 EB 实例和我的 Redis 端点之间创建连接的 Elastic Beanstalk 和 ElastiCache 文档。我已将我的端点添加到我的 Node.js 应用程序中的会话配置中,但它似乎没有连接到我的 Redis 实例,正如访问任何使用该会话的页面时抛出的错误所指示的那样。我知道 Elastic Beanstalk 和 ElastiCache 之间的安全组需要相同,但我是否需要调整我的环境以附加两者?

这是我的 Node.js 应用程序中的 Redis 连接:

//Session Cookie
app.use(cookieParser());
app.use(session({
    store: new RedisStore({
        host: 'redis-production.dfdfa.0001.use1.cache.amazonaws.com',
        port: 6379
    }), 
    secret: process.env.SECRET,
    resave: true,
    saveUninitialized: true,
    cookie: {
        httpOnly: true,
        secure: false //turn to true on production once https is in place
    }
}));

我不确定你的意思:

I know that the security groups between the Elastic Beanstalk and ElastiCache need to be the same

他们不需要是同一个安全组,如果您是这么说的话。如果这就是您所说的,它们不需要具有完全相同的设置。这是您需要做的:

  1. Elastic Beanstalk 服务器在特定的安全组中。我们将其称为 SG1。
  2. ElastiCache 实例在特定的安全组中。我们将其称为 SG2。
  3. 在 SG2 中添加一条规则,允许您在配置 ElastiCache 实例时指定的端口上的流量。默认端口为 6379。在此安全组规则中,在源字段中使用 SG1 的 ID。例如,如果 SG1 的 ID 为 sg-123456,则在源字段中输入该 ID。

完成这些步骤后,所有 Elastic Beanstalk 实例都可以访问您的 ElastiCache Redis 实例。