Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@Benjaminhu Benjaminhu commented Oct 18, 2020

Great bash memcached tool: membash.sh

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