我对 AWS CloudFront 和 AWS 总体来说是新手。我有一个 Next.js(React SSR 框架)网站,我使用 serverless-nextjs
( https://github.com/serverless-nextjs/serverless-next.js ) 将其部署到 AWS 上。但是,我还需要为我的网络应用程序进行某种缓存。我决定使用 AWS 的 redis ElastiCache。我在 AWS 控制台上创建了一个 redis ElastiCache 集群。
我的尝试:
我设置了用于连接到 Redis ElastiCache 的代码,如下所示:
import redis from 'redis';
...
export async function getServerSideProps() { // Server side function for Next.js
const cache = redis.createClient(6379, "{PRIMARY-ENDPOINT-URL-AWS}");
}
我在我的电脑上本地运行该网站。但是,我从 redis 收到超时错误:Error: connect ETIMEDOUT
。
我如何从 CloudFront 和本地 PC 连接到 Redis ElastiCache 集群?
redis ElastiCache Cluster 窗口的屏幕截图:
最佳答案
您无法从AWS外部直接连接到ES(即您的本地工作站)。 ES 域被设计为只能从与 ES 域位于同一 VPC 中的资源(例如实例)内访问。来自 docs :
Elasticache is a service designed to be used internally to your VPC. External access is discouraged due to the latency of Internet traffic and security concerns. However, if external access to Elasticache is required for test or development purposes, it can be done through a VPN.
启用从外部 AWS 到 ES 的连接的唯一方法是在家庭/工作网络或 Direct Connect 之间建立 VPN 连接,如 AWS docs 中所述。 :
This scenario is also supported providing there is connectivity between the customers’ VPC and the data center either through VPN or Direct Connect.
但是,为了快速进行临时设置,您可以在本地工作站和 ES 域之间使用 ssh 隧道。这将需要一些隧道将经过的跳转/基础 EC2 实例。
关于node.js - 如何使用 Node.js 从 AWS CloudFront 连接到 AWS ElastiCache 集群?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65638520/