Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
Add scripts to trigger scale in/out
Browse files Browse the repository at this point in the history
  • Loading branch information
akash1810 committed Sep 2, 2024
1 parent f13e703 commit 4a2be1b
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
46 changes: 46 additions & 0 deletions script/scale-in
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

set -e

CLOUDFORMATION_STACK_NAME=playground-CODE-scaling-asg-rolling-update

POLICY_ARN=$(
aws cloudformation describe-stacks \
--stack-name "$CLOUDFORMATION_STACK_NAME" \
--profile developerPlayground \
--region eu-west-1 \
--no-cli-pager | \
jq -r '.Stacks[].Outputs[] | select( [.OutputKey | contains("ScaleInArn") ] | any) | .OutputValue'
)

ASG_NAME=$(
aws cloudformation describe-stacks \
--stack-name "$CLOUDFORMATION_STACK_NAME" \
--profile developerPlayground \
--region eu-west-1 \
--no-cli-pager | \
jq -r '.Stacks[].Outputs[] | select( [.OutputKey | contains("AutoscalingGroupName") ] | any) | .OutputValue'
)

CURRENT_DESIRED_CAPACITY=$(
aws autoscaling describe-auto-scaling-groups \
--auto-scaling-group-names "$ASG_NAME" \
--profile developerPlayground \
--region eu-west-1 | \
jq -r '.AutoScalingGroups[].DesiredCapacity'
)

aws autoscaling execute-policy \
--policy-name "$POLICY_ARN" \
--profile developerPlayground \
--region eu-west-1

NEW_DESIRED_CAPACITY=$(
aws autoscaling describe-auto-scaling-groups \
--auto-scaling-group-names "$ASG_NAME" \
--profile developerPlayground \
--region eu-west-1 | \
jq -r '.AutoScalingGroups[].DesiredCapacity'
)

echo "Desired capacity has been updated from $CURRENT_DESIRED_CAPACITY to $NEW_DESIRED_CAPACITY"
46 changes: 46 additions & 0 deletions script/scale-out
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

set -e

CLOUDFORMATION_STACK_NAME=playground-CODE-scaling-asg-rolling-update

POLICY_ARN=$(
aws cloudformation describe-stacks \
--stack-name "$CLOUDFORMATION_STACK_NAME" \
--profile developerPlayground \
--region eu-west-1 \
--no-cli-pager | \
jq -r '.Stacks[].Outputs[] | select( [.OutputKey | contains("ScaleOutArn") ] | any) | .OutputValue'
)

ASG_NAME=$(
aws cloudformation describe-stacks \
--stack-name "$CLOUDFORMATION_STACK_NAME" \
--profile developerPlayground \
--region eu-west-1 \
--no-cli-pager | \
jq -r '.Stacks[].Outputs[] | select( [.OutputKey | contains("AutoscalingGroupName") ] | any) | .OutputValue'
)

CURRENT_DESIRED_CAPACITY=$(
aws autoscaling describe-auto-scaling-groups \
--auto-scaling-group-names "$ASG_NAME" \
--profile developerPlayground \
--region eu-west-1 | \
jq -r '.AutoScalingGroups[].DesiredCapacity'
)

aws autoscaling execute-policy \
--policy-name "$POLICY_ARN" \
--profile developerPlayground \
--region eu-west-1

NEW_DESIRED_CAPACITY=$(
aws autoscaling describe-auto-scaling-groups \
--auto-scaling-group-names "$ASG_NAME" \
--profile developerPlayground \
--region eu-west-1 | \
jq -r '.AutoScalingGroups[].DesiredCapacity'
)

echo "Desired capacity has been updated from $CURRENT_DESIRED_CAPACITY to $NEW_DESIRED_CAPACITY"

0 comments on commit 4a2be1b

Please sign in to comment.