Change EC2 instance type

主要是用 AWS 已經做好的 shell script 來運用

參考網址: https://docs.aws.amazon.com/cli/latest/userguide/cli-services-ec2-instance-type-script.html


以下是執行用的 script

#!/bin/bash

PATH=$PATH:/usr/local/bin

TIMESTAMP=$(date -u '+%Y-%m-%d` `date +%H:%M:%SZ')

NOW=$(date +"%F")


#echo -e "  ---- Step Time: `date +%Y-%m-%d` `date +%H:%M:%S` ----\n" >> /home/ubuntu/logfile/drupal_change.log

echo -e "  ---- Start Time: `date +%Y-%m-%d` `date +%H:%M:%S` ----\n" >> /home/ubuntu/logfile/drupal_status-$NOW.log

Drupal_current_instance=$(/usr/local/bin/aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceType]' --filters Name=instance-id,Values=$1 --output text)

echo -e "Current Instance Type: ${Drupal_current_instance}\n" >> /home/ubuntu/logfile/drupal_status-$NOW.log


source /home/ubuntu/awsdocs_general.sh

source /home/ubuntu/change_ec2_instance_type.sh

change_ec2_instance_type -f -r -i $1 -t $2


Drupal_changed_instance=$(/usr/local/bin/aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceType]' --filters Name=instance-id,Values=$1 --output text)

echo -e "  ----- Step Time: `date +%Y-%m-%d` `date +%H:%M:%S` ----\n" >> /home/ubuntu/logfile/drupal_status-$NOW.log

echo -e "Changed Instance Type: ${Drupal_changed_instance}\n" >> /home/ubuntu/logfile/drupal_status-$NOW.log

echo -e "  ------ End Time: `date +%Y-%m-%d` `date +%H:%M:%S` ----\n\n" >> /home/ubuntu/logfile/drupal_status-$NOW.log


留言