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.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南