본문 바로가기

Ops/AWS

AWS Gamelift - autoscaling script code (bash)

반응형

AWS Gamelift - autoscaling script code (bash)

 

 

 

Gamelift의 autoscaling 정책을 세팅하는 스크립트입니다.

 

# ------------------------------------------------------------------
# Title : Autoscaling Setting for Gamelift fleet Instance
# Data : 2020-06-02
# Author : Mit-Chandler
# Using : ./filename.sh region
# Copyright 2020. All rights reserved
# reference : https://docs.aws.amazon.com/ko_kr/gamelift/latest/developerguide/fleets-autoscaling-rule.html
# ------------------------------------------------------------------
#!/bin/bash
 
# variable
export REGIONID="$1"
 
if [ "${REGIONID}" = "" ]; then
    echo ""
    echo "You have to input region value."
    echo ""
    exit 1
fi
 
FLEETID=`aws gamelift list-fleets --region $REGIONID | grep fleet | awk -F \" '{print $2}'`
 
    echo 'check fleet id'
    echo -n 'FLEETID = ';echo $FLEETID
    echo
    echo 'fleet-capacity-start'
 
 
# min / target / max (need : FLEETID, REGIONID)
aws gamelift update-fleet-capacity \
    --fleet-id $FLEETID \
    --desired-instances 1 \
    --min-size 1 \
    --max-size 20 \
    --region $REGIONID
 
    echo
    echo
    echo 'scaling-in-policy-start'
 
# role : available game session > 80%, and reduce instance 1
aws gamelift put-scaling-policy \
    --fleet-id $FLEETID \
    --name "Scale in when AGS>80" \
    --policy-type RuleBased \
    --metric-name PercentAvailableGameSessions \
    --comparison-operator GreaterThanThreshold \
    --threshold 80 \
    --evaluation-periods 5 \
    --scaling-adjustment-type ChangeInCapacity \
    --scaling-adjustment -1 \
    --region $REGIONID
 
    echo
    echo
    echo 'scaling-out-policy-start'
 
# role : available game session < 50%, and add instance 2
aws gamelift put-scaling-policy \
    --fleet-id "${FLEETID}" \
    --name "Scale out when AGS<50" \
    --policy-type RuleBased \
    --metric-name PercentAvailableGameSessions \
    --comparison-operator LessThanThreshold \
    --threshold 50 \
    --evaluation-periods 1 \
    --scaling-adjustment-type ChangeInCapacity \
    --scaling-adjustment 2 \
    --region $REGIONID
 
    echo
    echo
    echo 'all done'
    echo
 
# delete
# aws gamelift delete-scaling-policy \
#    --fleet-id $FLEETID \
#    --name "Scale out when AGS<50" \
#    --region $REGIONID
     
# aws gamelift delete-scaling-policy --fleet-id fleet-11111111-2222-3333-4444-555555555555 --name "Scale in when AGS>80"

 

 

 


by mkdir-chandler


 

 

 

 

 

728x90
반응형