Module resty.aws.service.elasticache.signer

Signer class for Elasticache tokens for Valkey and Redis OSS access.

Functions

Signer:getAuthToken (opts) The example shows how to use getAuthToken to create an authentication token for connecting to a PostgreSQL database in RDS.


Functions

Signer:getAuthToken (opts)
The example shows how to use getAuthToken to create an authentication token for connecting to a PostgreSQL database in RDS.

Parameters:

  • opts configuration to use, to override the options inherited from the underlying AWS instance;
    • region string The AWS region
    • cachename string the Elasticache instance name to connect to, eg. "test-cache"
    • username string name of the IAM-enabled user configured in the Elasticache User management page.
    • is_serverless boolean the deployment mode of the cache cluster.
    • credentials Credentials aws credentials

Returns:

    token, err - Returns the token to use as the password for the Redis connection, or nil and error if an error occurs

Usage:

    local AWS = require("resty.aws")
    local AWS_global_config = require("resty.aws.config").global
    local aws = AWS { region = AWS_global_config.region }
    local cache = aws:ElastiCache()
    local redis = require "resty.redis"
    
    local hostname = "HOSTNAME, e.g. test-cache-ppl9c2.serverless.apne1.cache.amazonaws.com"
    local cachename = "CACHE CLUSTER NAME, e.g. test-cache"
    local port = 6379
    local name = "Username e.g. test-user"
    
    local signer = cache:Signer {  -- create a signer instance
      cachename = cachename,
      username = name,
      is_serverless = true,
      region = nil,              -- will be inherited from aws
      credentials = nil,         -- will be inherited from aws
    }
    
    -- use the 'signer' to generate the token, whilst overriding some options
    local auth_token, err = signer:getAuthToken()
    
    if err then
      ngx.log(ngx.ERR, "Failed to build auth token: ", err)
      return
    end
    print(auth_token)
    
    local red = redis:new()
    --red:set_timeouts(1000, 1000, 1000)
    
    local ok, err = red:connect(hostname, port, { ssl = true })
    if not ok then
      print("failed to connect: ", err)
      return
    end
    
    local res, err = red:auth(name, auth_token)
    if not res then
      print("failed to authenticate: ", err)
      return
    end
    
    print("OK")
generated by LDoc 1.5.0 Last updated 2025-11-10 13:27:37