Amazon MemoryDB and ElastiCache#
This page provisions an Amazon MemoryDB for Valkey cluster for Live Edit’s backing store, with IAM authentication, and connects Live Edit to it. Read Backing store first for the requirements and sizing model. MemoryDB writes every change to a Multi-AZ transaction log before acknowledging it, so a node or zone failure loses no committed edit. ElastiCache for Valkey (node-based) works with the differences listed below.
You need a VPC with private subnets in at least two availability zones, a security group for the cluster, and an EKS cluster with an OIDC provider.
Parameters#
REGION={AWS_REGION}
ACCOUNT={AWS_ACCOUNT_ID}
EKS={EKS_CLUSTER}
CLUSTER=live-edit-mdb
NODE_TYPE=db.r7g.large # development: db.t4g.small
SUBNET_GROUP=live-edit-subnets
SECURITY_GROUP={SECURITY_GROUP_ID}
PARAM_GROUP=default.memorydb-valkey7 # already noeviction
ACL_USER=live-edit
ACL=live-edit-acl
IAM_ROLE=live-edit-memorydb
NAMESPACE=storage-apis
SA=live-edit-service # the chart's ServiceAccount, or your serviceAccount.name
1. Check the eviction policy#
The default parameter group already sets noeviction.
If you use a custom group, set maxmemory-policy to noeviction in it.
Verify:
aws memorydb describe-parameters --parameter-group-name "$PARAM_GROUP" --region "$REGION" \
--query "Parameters[?Name=='maxmemory-policy'].Value" --output text # noeviction
2. Create the subnet group#
aws memorydb create-subnet-group --subnet-group-name "$SUBNET_GROUP" \
--subnet-ids {SUBNET_A} {SUBNET_B} --region "$REGION"
3. Create the IAM-enabled user#
aws memorydb create-user --user-name "$ACL_USER" \
--authentication-mode Type=iam \
--access-string "on ~le:* &le:* +@all" --region "$REGION"
aws memorydb create-acl --acl-name "$ACL" --user-names "$ACL_USER" --region "$REGION"
For a development cluster without IAM, use --authentication-mode Type=password,Passwords={PASSWORD} and static authentication with rediss-cluster://{ACL_USER}:{PASSWORD}@{ENDPOINT}:6379 in the live-edit-env Secret.
4. Create the cluster#
aws memorydb create-cluster --cluster-name "$CLUSTER" \
--node-type "$NODE_TYPE" --engine valkey \
--num-shards 2 --num-replicas-per-shard 1 \
--acl-name "$ACL" --parameter-group-name "$PARAM_GROUP" \
--subnet-group-name "$SUBNET_GROUP" --security-group-ids "$SECURITY_GROUP" \
--tls-enabled --region "$REGION"
aws ec2 authorize-security-group-ingress --group-id "$SECURITY_GROUP" \
--protocol tcp --port 6379 \
--source-group {EKS_NODE_OR_CLUSTER_SECURITY_GROUP} --region "$REGION"
The ingress rule admits the pods; without it every connection times out.
For development, use --node-type db.t4g.small --num-shards 1 --num-replicas-per-shard 0.
Do not use t4g nodes in production: sustained script load exhausts their CPU credits.
5. Create the IAM role#
OIDC=$(aws eks describe-cluster --name "$EKS" --region "$REGION" \
--query 'cluster.identity.oidc.issuer' --output text | sed 's~https://~~')
cat > trust-policy.json <<EOF
{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow",
"Principal": { "Federated": "arn:aws:iam::${ACCOUNT}:oidc-provider/${OIDC}" },
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": { "StringEquals": {
"${OIDC}:sub": "system:serviceaccount:${NAMESPACE}:${SA}",
"${OIDC}:aud": "sts.amazonaws.com" } } }] }
EOF
cat > connect-policy.json <<EOF
{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow",
"Action": "memorydb:connect",
"Resource": [ "arn:aws:memorydb:${REGION}:${ACCOUNT}:cluster/${CLUSTER}",
"arn:aws:memorydb:${REGION}:${ACCOUNT}:user/${ACL_USER}" ] }] }
EOF
aws iam create-role --role-name "$IAM_ROLE" --assume-role-policy-document file://trust-policy.json
aws iam put-role-policy --role-name "$IAM_ROLE" --policy-name memorydb-connect \
--policy-document file://connect-policy.json
6. Connect Live Edit#
Read the endpoint:
aws memorydb describe-clusters --cluster-name "$CLUSTER" --region "$REGION" \
--query 'Clusters[0].ClusterEndpoint.Address' --output text
Start from the complete values example.
Replace its valkey block and its serviceAccount annotation with these.
The IAM role authenticates Live Edit to MemoryDB only; the backing store needs no token file:
serviceAccount:
annotations:
eks.amazonaws.com/role-arn: "arn:aws:iam::{AWS_ACCOUNT_ID}:role/live-edit-memorydb"
valkey:
url:
value: "rediss-cluster://{CLUSTER_ENDPOINT}:6379"
credentials:
awsIam:
enabled: true
service: memorydb
username: "live-edit"
region: "{AWS_REGION}"
clusterHost: "live-edit-mdb" # the cluster name, not the endpoint
After installing, check that the pods are ready and that live_edit_store_memory_used_ratio reports a value within a minute.
Leave valkey.memoryBytes unset: MemoryDB and ElastiCache report their memory limit.
With checkpoints disabled, a startup warning could not verify Valkey AOF state is expected: MemoryDB blocks CONFIG, and its transaction log replaces AOF.
Checkpoints to the Storage API on AWS#
Live Edit needs a Storage service token only when checkpoints go to the Storage API (checkpoint.adapter: StorageApi).
The IAM role cannot produce that token.
Your token provisioner must obtain it from the identity provider your Storage API trusts, for example through a client-credentials flow with the client secret in a Kubernetes Secret, and write it in the token file format.
Without such a provisioner, drop the complete example’s serviceIdentity block and its StorageApi checkpoint settings, and choose another option from Durability; MemoryDB’s transaction log and snapshots already protect against node and zone failure.
ElastiCache for Valkey#
Apply the same eviction, TLS, cluster-mode and access-string settings, and change:
Setting |
MemoryDB |
ElastiCache for Valkey |
|---|---|---|
|
|
|
IAM action to grant on the cache and user |
|
|
|
cluster name |
replication group or cache name |
Grant elasticache:Connect on arn:aws:elasticache:{AWS_REGION}:{AWS_ACCOUNT_ID}:replicationgroup:{NAME} and arn:aws:elasticache:{AWS_REGION}:{AWS_ACCOUNT_ID}:user:{USER}.
Create the ElastiCache user with identical user name and user ID.
ElastiCache reserves 25 % of node memory by default (reserved-memory-percent), so choose a node whose remaining memory is about twice your expected peak.
ElastiCache replication is asynchronous: configure durability as for any store without a transaction log.
Sizing#
Memory: choose a node type whose published
maxmemoryis about twice your expected peak per shard (db.r7g.large: about 13 GiB). To tell when it is filling up, see Store memory.CPU: prefer
r7gnodes, and add shards for write headroom.Connections: the limit is 65,000 per node, about six times the rollout peak at the chart defaults.
Durability#
MemoryDB needs no AOF, and its snapshots add point-in-time restore. Checkpoints are optional; add them if you need recovery from deletion or loss of the whole cluster (Durability).
Limitations#
While MemoryDB or ElastiCache moves data between shards, writes to the layers and sessions being moved can be refused, and their backups can lag, until their move ends, as When the store moves data between shards describes.
References#
MemoryDB IAM authentication: users and
memorydb:connect.MemoryDB parameters:
maxmemoryper node type andmaxclients.ElastiCache reserved memory:
reserved-memory-percent.ElastiCache IAM authentication: users, ARNs and
elasticache:Connect.IAM roles for service accounts: IRSA setup.
See next#
Durability: decide whether to add checkpoints.