sh AWS EC2自动恢复
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh AWS EC2自动恢复相关的知识,希望对你有一定的参考价值。
#!/bin/bash
if [ $# -ne 2 ]; then
echo "Usage: $0 [AlarmBaseName] [Region]"
echo "Region: ap-northeast-1 ap-southeast-1 ap-southeast-2 eu-central-1 eu-west-1 sa-east-1 us-east-1 us-west-1 us-west-2"
exit
fi
ALARM_BASE_NAME=$1
METRIC_NAME=StatusCheckFailed_System
NAMESPACE=AWS/EC2
STATISTIC=Maximum
PERIOD=60
EVALUATION_PERIODS=1
THRESHOLD=1
COMPARISON_OPERATOR=GreaterThanOrEqualToThreshold
ALARM_ACTIONS=arn:aws:automate:$2:ec2:recover
#PROFILE="--profile profname"
for INSTANCE_ID in $(aws ec2 $PROFILE describe-instances | jq -r '.Reservations[].Instances[].InstanceId');
do
NODE_NAME=$(aws ec2 $PROFILE describe-tags --filters "Name=resource-id,Values=${INSTANCE_ID}" "Name=key,Values=Name" --query "Tags[*].Value" --output text)
aws cloudwatch put-metric-alarm \
--alarm-name $ALARM_BASE_NAME-$NODE_NAME \
--alarm-actions $ALARM_ACTIONS \
--metric-name $METRIC_NAME \
--namespace $NAMESPACE \
--dimensions Name=InstanceId,Value=$INSTANCE_ID \
--statistic $STATISTIC \
--period $PERIOD \
--evaluation-periods $EVALUATION_PERIODS \
--threshold $THRESHOLD \
--comparison-operator $COMPARISON_OPERATOR
if [ $? != 0 ]; then
echo "Failed!: ${NODE_NAME}"
fi
done
以上是关于sh AWS EC2自动恢复的主要内容,如果未能解决你的问题,请参考以下文章
恢复丢失的 AWS EC2 密钥对
sh AWS CLI:使用标记值描述EC2实例
sh 通过ssh在aws ec2 ubuntu实例中安装节点
sh 使用AWS控制台创建EBS卷并将其附加到EC2实例
sh [在AWS EC2 Linux服务器上从PHP 5.X.X升级到PHP 7] #linux #aws
sh 构建Docker镜像,将其推送到AWS EC2 Container Registry,然后将其部署到AWS Elastic Beanstalk