Skip to content

Configure AWS IAM Authentication

GLIDE 2.2+ provides built-in support for AWS Identity and Access Management (IAM) authentication when connecting to Amazon ElastiCache and MemoryDB clusters. This feature automatically handles token generation and rotation, making it simple to maintain secure connections.

  • GLIDE automatically generates temporary authentication tokens that are valid for 15 minutes
  • GLIDE refreshes the token every 5 minutes (default). On failure, it retries with exponential backoff and keeps using the last valid token until a new one is obtained
  • When a new token is available, GLIDE updates its cached credentials. New and reconnecting connections use the fresh token, while pooled and isolated connections reconcile token changes before an eligible command
  • During reconnection, GLIDE checks whether the cached token has expired (age ≥ 15 minutes). If so, it generates a fresh token before attempting to reconnect, ensuring a valid credential is used even when connections have been idle
  • GLIDE handles re-authentication automatically when required, for example when ElastiCache or MemoryDB terminates a session after its maximum lifetime
  • GLIDE handles all token management, refresh operations, and re-authentication behind the scenes
  • On-demand token refresh is available via refreshIamToken (see On-Demand Refresh below)
  1. AWS Credentials: Unless you configure a custom AWS credential provider, your application must run in an environment where the default AWS credential chain can find credentials, such as an EC2 instance with an IAM role or an ECS task with a task role.

  2. TLS: IAM authentication requires TLS. GLIDE rejects an IAM client configuration when TLS is disabled.

  3. Required Information:

  • username: Your ElastiCache/MemoryDB username
  • cluster_name: Your cluster’s name
  • service: Either ElastiCache or MemoryDB
  • region: The AWS region where your cluster runs
  • refresh_interval_seconds (Optional): How often to refresh the token. Default is 300 seconds (5 minutes)

The cluster name and region must not be blank, and the username must not be empty.

import java.util.Collections;
import java.util.List;
import glide.api.GlideClusterClient;
import glide.api.models.configuration.GlideClusterClientConfiguration;
import glide.api.models.configuration.IamAuthConfig;
import glide.api.models.configuration.NodeAddress;
import glide.api.models.configuration.ServerCredentials;
import glide.api.models.configuration.ServiceType;
...
List<NodeAddress> nodeList =
Collections.singletonList(
NodeAddress.builder().host("endpoint.example.com").port(6379).build());
// Configure IAM authentication
// Automatically regenerates the token every 5 mins (default: 300 seconds)
IamAuthConfig iamConfig =
IamAuthConfig.builder()
.clusterName("clustername")
.service(ServiceType.ELASTICACHE) // or ServiceType.MEMORYDB
.region("us-east-1")
// .refreshIntervalSeconds(100) // Optional, default is 300 seconds
.build();
GlideClusterClientConfiguration config =
GlideClusterClientConfiguration.builder()
.addresses(nodeList)
.useTLS(true)
.credentials(
ServerCredentials.builder()
.username("username")
.iamConfig(iamConfig)
.build())
.build();
GlideClusterClient client = GlideClusterClient.createClient(config).get();
...

Python, Java, Node.js, and Go direct clients can obtain AWS credentials from an application callback instead of the default AWS credential chain. Use this for credential stores or custom assume-role flows that the default chain cannot resolve.

The provider must return a non-blank access key ID and secret access key. A session token and expiration time are optional. GLIDE can invoke the provider during client creation, token refresh, or reconnection, so it must return current credentials and tolerate repeated calls.

import java.util.concurrent.CompletableFuture;
import glide.api.models.configuration.AwsCredentials;
import glide.api.models.configuration.IamAuthConfig;
import glide.api.models.configuration.ServiceType;
IamAuthConfig iamConfig =
IamAuthConfig.builder()
.clusterName("clustername")
.service(ServiceType.ELASTICACHE)
.region("us-east-1")
.credentialsProvider(
() ->
CompletableFuture.completedFuture(
AwsCredentials.builder()
.accessKeyId("access-key-id")
.secretAccessKey("secret-access-key")
.build()))
.build();

You can call refreshIamToken (or language equivalent) at any time to immediately request a fresh token from AWS and update the internal token cache.

// Pre-warm the token cache before a maintenance window
client.refreshIamToken().get();