如何在我的情况下连接到elasticache?

我试图从我的应用程序连接到aws elasticache。

我知道端点和端口,但由于某种原因,我无法连接到它。

我使用了这个npm包: https ://www.npmjs.com/package/node-memcached-client

码:

const Memcached = require('node-memcached-client'); const client = new Memcached({ host: 'mycache.aa11c.0001.use2.cache.amazonaws.com', //fake aws cache endpoint port: 11211 }); console.log(client); // I can see it outputs stuff client.connect() .then(c => { console.log('connected'); console.log(c); }).catch(function(err){ console.log('error connecting'); console.log(err); }); 

出于某种原因,当我运行代码时,我所看到的就是

 [Memcached] INFO: Nothing any connection to mycache.aa11c.0001.use2.cache.amazonaws.com:11211, created sid:1 

console.log没有错误或connected消息。 我在这里做错了什么?

谢谢!

您可能需要从AWS的以下文档中查看AWS以外的Elasticache资源:

从外部访问AWS Elasticache

我build议设置一个用于开发和debugging的本地memcached实例,并在testing和生产环境中从EC2实例连接到Elasticache。

除非绝对必要,否则尝试设置NAT和映射IP地址的ROI对开发/testing来说是不合理的。

我结束了使用端口转发绕过本地实例无法连接到elasticache问题。

通过使用

 ssh -L 11211:{your elasticache endpoint}:11211 {your ec2 instance ip}