1

I am using go-redis library to use AWS MemoryDB cluster as a database.

I am able to connect to cluster with VPN connection, however

the following cli command connects to database:

redis-cli --tls -u redis://<memory-db-endpoint> -p 6379

but the following Go code does not work and get i/o timeout error.

conf, err := redis.ParseURL("redis://$CLUSTER_ENDPOINT:6379")
if err != nil {
   panic(err)
}

cl := redis.NewClient(conf)
res, err := cl.Ping(context.Background()).Result()
if err != nil {
    panic(err)
}

what is needed to establish a connection with a single node AWS MemoryDB cluster?

Harun Sasmaz
  • 119
  • 1
  • 1
  • 10
  • Are you literally passing `"redis://$CLUSTER_ENDPOINT:6379"`, or are you just redacting `$CLUSTER_ENDPOINT`? – Gavin Apr 18 '23 at 20:38

2 Answers2

2

Redis URIs with TLS must begin with "rediss://", not "redis://"; see https://www.iana.org/assignments/uri-schemes/prov/rediss for more information.

This code works:

conf, err := redis.ParseURL("rediss://$CLUSTER_ENDPOINT:6379")
if err != nil {
   panic(err)
}

cl := redis.NewClient(conf)
res, err := cl.Ping(context.Background()).Result()
if err != nil {
    panic(err)
}
Bar Shaul
  • 124
  • 1
  • 4
1

The problem is go-redis library does not know how to get system certificates for TLS connections.

So, here is how to pass system certificate pool to connection config.

...

pool, err := x509.SystemCertPool()
if err != nil {
   panic(err)
}

conf.TLSConfig = &tls.Config{
    RootCAs: pool,
}

...
Harun Sasmaz
  • 119
  • 1
  • 1
  • 10