From 66132f3db781ede16492f3aeb97d2ed3935d09a0 Mon Sep 17 00:00:00 2001 From: yaakov Date: Fri, 17 Jan 2020 14:35:10 -0500 Subject: [PATCH 1/3] Adding instance-change-type function --- aliases | 3 ++- lib/instance-functions | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/aliases b/aliases index d364e37e..317009c2 100644 --- a/aliases +++ b/aliases @@ -69,6 +69,7 @@ alias images='~/.bash-my-aws/bin/bma images' alias instance-asg='~/.bash-my-aws/bin/bma instance-asg' alias instance-az='~/.bash-my-aws/bin/bma instance-az' alias instance-console='~/.bash-my-aws/bin/bma instance-console' +alias instance-change-type='~/.bash-my-aws/bin/bma instance-change-type' alias instance-dns='~/.bash-my-aws/bin/bma instance-dns' alias instance-health-set-unhealthy='~/.bash-my-aws/bin/bma instance-health-set-unhealthy' alias instance-iam-profile='~/.bash-my-aws/bin/bma instance-iam-profile' @@ -167,4 +168,4 @@ function region() { else AWS_DEFAULT_REGION="$inputs"; fi -} \ No newline at end of file +} diff --git a/lib/instance-functions b/lib/instance-functions index 7bc4d0f4..94cc2188 100644 --- a/lib/instance-functions +++ b/lib/instance-functions @@ -42,6 +42,18 @@ instances() { column -s$'\t' -t } +instance-change-type() { + + # Change an instance type + # + # USAGE: instance-change-type [instance-id instance-type] + + [[ $# != 2 ]] && __bma_usage "instance-id [instance-id] [instance-type]" && return 1 + + aws ec2 modify-instance-attribute \ + --instance-id $1 \ + --instance-type $2 +} instance-asg() { From 9864258b9bbd29ce02641ce45873ddccb2939f4c Mon Sep 17 00:00:00 2001 From: yaakov Date: Fri, 17 Jan 2020 14:42:29 -0500 Subject: [PATCH 2/3] typo --- lib/instance-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/instance-functions b/lib/instance-functions index 94cc2188..e7282184 100644 --- a/lib/instance-functions +++ b/lib/instance-functions @@ -46,7 +46,7 @@ instance-change-type() { # Change an instance type # - # USAGE: instance-change-type [instance-id instance-type] + # USAGE: instance-change-type [instance-id] [instance-type] [[ $# != 2 ]] && __bma_usage "instance-id [instance-id] [instance-type]" && return 1 From a6928ecff07cbe374eb3546046dd9b2faaeaacb9 Mon Sep 17 00:00:00 2001 From: yaakov Date: Fri, 24 Apr 2020 12:15:33 -0400 Subject: [PATCH 3/3] adding modifications from PR review --- lib/instance-functions | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/instance-functions b/lib/instance-functions index e7282184..78d14993 100644 --- a/lib/instance-functions +++ b/lib/instance-functions @@ -46,13 +46,23 @@ instance-change-type() { # Change an instance type # - # USAGE: instance-change-type [instance-id] [instance-type] + # USAGE: instance-change-type instance-type instance-id [instance-id] - [[ $# != 2 ]] && __bma_usage "instance-id [instance-id] [instance-type]" && return 1 + [[ $# != 2 ]] && __bma_usage "instance-change-type instance-type instance-id [instance-id]" && return 1 + local type=$1 + shift + local instance_ids=$(skim-stdin "$@") + local regex_yes="^[Yy]$" - aws ec2 modify-instance-attribute \ - --instance-id $1 \ - --instance-type $2 + read -p "Are you sure you want to change these instances to $type? " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + for id in $instance_ids; do + aws ec2 modify-instance-attribute \ + --instance-type $type \ + --instance-id $id + done + fi } instance-asg() {