Skip to content

Instantly share code, notes, and snippets.

@Benjaminhu
Last active October 18, 2020 09:38
Show Gist options
  • Save Benjaminhu/0d45644ee60be38ba5f7dbea349de84a to your computer and use it in GitHub Desktop.
Save Benjaminhu/0d45644ee60be38ba5f7dbea349de84a to your computer and use it in GitHub Desktop.
AWS - ElastiCache for Memcached - bash query first node - Auto Discovery cluster node
#!/bin/bash
# https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/AutoDiscovery.html
#
# ConfigurationEndpoint example: mycluster.fnjyzo.cfg.use1.cache.amazonaws.com
#
# CacheNodes Endpoint 1: mycluster.fnjyzo.cfg.0001.use1.cache.amazonaws.com
# CacheNodes Endpoint 2: mycluster.fnjyzo.cfg.0002.use1.cache.amazonaws.com
#
# Queries and returns the SORTED FIRST item
# MEMCACHED_HOST=$(get_memcached_node)
# echo $MEMCACHED_HOST
function get_memcached_node()
{
local cluster_id="<<< YOUR CLUSTER ID >>>"
local memcached_node
memcached_node=$(aws elasticache describe-cache-clusters \
--cache-cluster-id "${cluster_id}" \
--show-cache-node-info \
--query 'CacheClusters[*].CacheNodes[*].Endpoint.Address' \
--output text \
| sed 's/\t/\n/g' \
| sort --ignore-case \
| head --lines=1
)
echo "$memcached_node"
}
@Benjaminhu
Copy link
Author

Great bash memcached tool: membash.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment