Last active
October 18, 2020 09:38
-
-
Save Benjaminhu/0d45644ee60be38ba5f7dbea349de84a to your computer and use it in GitHub Desktop.
AWS - ElastiCache for Memcached - bash query first node - Auto Discovery cluster node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great bash memcached tool: membash.sh