@@ -939,6 +939,61 @@ Resources:
939
939
AutoScalingReplacingUpdate :
940
940
WillReplace : true
941
941
942
+ AsgProcessSuspenderRole :
943
+ Type : AWS::IAM::Role
944
+ Properties :
945
+ AssumeRolePolicyDocument :
946
+ Version : 2012-10-17
947
+ Statement :
948
+ - Effect : Allow
949
+ Principal :
950
+ Service :
951
+ - lambda.amazonaws.com
952
+ Action :
953
+ - sts:AssumeRole
954
+ ManagedPolicyArns :
955
+ - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
956
+ Policies :
957
+ - PolicyName : AsgProcessModification
958
+ PolicyDocument :
959
+ Version : 2012-10-17
960
+ Statement :
961
+ - Effect : Allow
962
+ Action :
963
+ - ' autoscaling:SuspendProcesses'
964
+ Resource : !Sub arn:${AWS::Partition}:autoscaling:${AWS::Region}:${AWS::AccountId}:autoScalingGroup:*:autoScalingGroupName/${AgentAutoScaleGroup}
965
+
966
+ AzRebalancingSuspenderFunction :
967
+ Type : AWS::Lambda::Function
968
+ Properties :
969
+ Description : ' Disables AZ Rebalancing on the agent ASG'
970
+ Code :
971
+ ZipFile : |
972
+ import cfnresponse
973
+ import boto3
974
+ def handler(event, context):
975
+ try:
976
+ if event['RequestType'] == 'Delete':
977
+ cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, "CustomResourcePhysicalID")
978
+ else:
979
+ client = boto3.client('autoscaling')
980
+ props = event['ResourceProperties']
981
+ response = client.suspend_processes(AutoScalingGroupName=props['AutoScalingGroupName'], ScalingProcesses=['AZRebalance'])
982
+ cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, "CustomResourcePhysicalID")
983
+ except BaseException as err:
984
+ print('ERROR: ', err)
985
+ cfnresponse.send(event, context, cfnresponse.FAILED, {}, "CustomResourcePhysicalID")
986
+ Handler : index.handler
987
+ Role : !GetAtt AsgProcessSuspenderRole.Arn
988
+ Runtime : ' python3.7'
989
+
990
+ AzRebalancingSuspender :
991
+ Type : AWS::CloudFormation::CustomResource
992
+ Version : 1.0
993
+ Properties :
994
+ ServiceToken : !GetAtt AzRebalancingSuspenderFunction.Arn
995
+ AutoScalingGroupName : !Ref AgentAutoScaleGroup
996
+
942
997
SecurityGroup :
943
998
Type : AWS::EC2::SecurityGroup
944
999
Condition : CreateSecurityGroup
0 commit comments