IAM auth for ClusterClient using go-redis

125 Views Asked by At

I am using go-redis package to interface with AWS elasticache for Redis using redis.NewClusterClient. I am authenticating into the redis instance like so,

import "github.com/go-redis/redis/v8"

func InitRedis() {
    RedisClient := redis.NewClusterClient(redis.ClusterOptions{
        Addrs:     []string{"redis-address"},
        Password:  "redis-password",
        PoolSize:  10,
    })

    _, err := RedisClient.Ping().Result()
    if err != nil {
        log.Error(err, "could not establish connection")
        return
    }
}

With the recent addition of support for IAM auth for redis clusters, I'm looking to move away from the password usage and migrate to using IAM auth. I saw this example on authenticating using CredentialsProvider for a redis Client. However, I cannot see how I can do the same for a ClusterClient since the ClusterOptions struct does not seem to have support for CredentialsProvider. How should I go about authenticating into elasticache redis using IAM for a ClusterClient with the go-redis package?

Referred to https://github.com/redis/go-redis/discussions/2343, https://docs.amazonaws.cn/en_us/AmazonElastiCache/latest/red-ug/auth-iam.html

0

There are 0 best solutions below