ElastiCache Reids connection fail from ECS.

0

Redis Configuration information
Deploy Option : Serverless
Secure : AWS KMS, Encryption in transit enabled, No access control
Secure Group : 6379 = 0.0.0.0/0
AZ : ap-northeast-2a, ap-northeast-2b, ap-northeast-2c Public subnet
(VPC and Subnet were created custom.)

ECS - Task Configuration information
Type : AWS Rargate
OS : Linux/X86_64
Roles : ecsTaskExecutionRole, ecsTaskExecutinRole
Container Port: 3000
CPU/RAM : 0.25 / 0.5

ECS - Service Configuration information
Capacity provider strategy : Fargate / 0 / 1 / Latest
Deploy : Service, 1 Task
Subnet: Private Subnet
Network : Public IP ON
Secure Group : 80 = 0.0.0.0/0, 6378 = 0.0.0.0/0

Settings other than the above are default settings. NAT Gateway is set in the VPC Private Subnet, and all other ECS deployed in the Private Subnet are serviced over the Internet.

I confirmed that Redis was connected normally to the Private EC2 instance using the command below.

$ redis-cli -h [redis name]serverless.apn2.cache.amazonaws.com --tls -p 6379

Redis connection test code (node.js)

import express from 'express';
import { createClient } from 'redis';

const app = express();
const port = 3000;
const redisConf = {
	url: 'redis://[redis name].serverless.apn2.cache.amazonaws.com:6379',
	socket: {
		tls: true,
	},
};
const redis = await createClient(redisConf);
setInterval(() => {
	console.log('redis : ' + JSON.stringify(redis));
}, 10000);

app.get('/', async (req, res) => {
	console.log('redis : ' + JSON.stringify(redis));
	res.send('Hello World!');
});

app.listen(port, () => {
	console.log(`Example app listening at ${port}`);
});

how to properly connect to Redis?

kp
已提问 5 个月前245 查看次数
1 回答
0

Hi,

I am not sure if this's the case, but I met before rediss:// as declaration that it will be TLS connection (I see you defined it differently below)

To connect to a different host or port, use a connection string in the format redis[s]://[[username][:password]@][host][:port][/db-number]:

profile picture
专家
已回答 5 个月前
  • A basic part was overlooked. However, even if the "rediss" protocol is applied, the connection still fails. Is there anything else I should check?

  • As an additional note, there were no user settings (ID, PW) when configuring serverless redis.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则