🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

AWS Tutorials: How to Shutdown (Stop / Start) ElastiCache Service in AWS

ElastiCache does not support direct stopping and starting of clusters. Instead, the best way to minimize the cost of ElastiCache when it’s not in use is to scale down the cluster to the minimum configuration or to take snapshots of your data, delete the cluster, and recreate it when needed.

Scaling Down the Cluster

You can scale down the ElastiCache cluster to the minimum configuration to reduce costs. This involves reducing the number of nodes and changing the instance type to a smaller, less expensive one.

AWS CLI Commands

aws elasticache modify-cache-cluster --cache-cluster-id your-cache-cluster-id --num-cache-nodes 1 --cache-node-type cache.t2.micro --apply-immediately

Script for Scaling Down and Restoring ElastiCache Cluster

#!/bin/bash
# Define your ElastiCache cluster identifier and configuration
CACHE_CLUSTER_ID="your-cache-cluster-id"
SNAPSHOT_NAME="your-snapshot-name"
CACHE_NODE_TYPE="cache.t2.micro" # Example node type
NUM_CACHE_NODES=1
# Function to scale down the ElastiCache cluster
scale_down_elasticache() {
echo "Scaling down ElastiCache cluster: $CACHE_CLUSTER_ID"
aws elasticache modify-cache-cluster --cache-cluster-id $CACHE_CLUSTER_ID --num-cache-nodes $NUM_CACHE_NODES --cache-node-type $CACHE_NODE_TYPE --apply-immediately
if [ $? -eq 0 ]; then
echo "ElastiCache cluster scaled down successfully."
else
echo "Failed to scale down ElastiCache cluster."
fi
}
# Function to create a snapshot and delete the ElastiCache cluster
snapshot_and_delete_elasticache() {
echo "Creating snapshot for ElastiCache cluster: $CACHE_CLUSTER_ID"
aws elasticache create-snapshot --cache-cluster-id $CACHE_CLUSTER_ID --snapshot-name $SNAPSHOT_NAME
if [ $? -eq 0 ]; then
echo "Snapshot created successfully. Deleting ElastiCache cluster: $CACHE_CLUSTER_ID"
aws elasticache delete-cache-cluster --cache-cluster-id $CACHE_CLUSTER_ID
if [ $? -eq 0 ]; then
echo "ElastiCache cluster deleted successfully."
else
echo "Failed to delete ElastiCache cluster."
fi
else
echo "Failed to create snapshot."
fi
}
# Function to restore the ElastiCache cluster from a snapshot
restore_elasticache() {
echo "Restoring ElastiCache cluster: $CACHE_CLUSTER_ID from snapshot: $SNAPSHOT_NAME"
aws elasticache create-cache-cluster --cache-cluster-id $CACHE_CLUSTER_ID --snapshot-name $SNAPSHOT_NAME --cache-node-type $CACHE_NODE_TYPE --num-cache-nodes $NUM_CACHE_NODES
if [ $? -eq 0 ]; then
echo "ElastiCache cluster restored successfully."
else
echo "Failed to restore ElastiCache cluster."
fi
}
# Main script logic
case "$1" in
scale-down)
scale_down_elasticache
;;
snapshot-and-delete)
snapshot_and_delete_elasticache
;;
restore)
restore_elasticache
;;
*)
echo "Usage: $0 {scale-down|snapshot-and-delete|restore}"
exit 1
;;
esac
Subscribe
Notify of
guest


0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x