Skip to content

Commit

Permalink
Merge pull request #751 from buildkite/disable-az-rebalancing
Browse files Browse the repository at this point in the history
The agent autoscaling group should never rebalance availability zones
  • Loading branch information
yob authored Oct 22, 2020
2 parents b65b7be + db1040c commit cc93588
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions templates/aws-stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,61 @@ Resources:
AutoScalingReplacingUpdate:
WillReplace: true

AsgProcessSuspenderRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: AsgProcessModification
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'autoscaling:SuspendProcesses'
Resource: !Sub arn:${AWS::Partition}:autoscaling:${AWS::Region}:${AWS::AccountId}:autoScalingGroup:*:autoScalingGroupName/${AgentAutoScaleGroup}

AzRebalancingSuspenderFunction:
Type: AWS::Lambda::Function
Properties:
Description: 'Disables AZ Rebalancing on the agent ASG'
Code:
ZipFile: |
import cfnresponse
import boto3
def handler(event, context):
try:
if event['RequestType'] == 'Delete':
cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, "CustomResourcePhysicalID")
else:
client = boto3.client('autoscaling')
props = event['ResourceProperties']
response = client.suspend_processes(AutoScalingGroupName=props['AutoScalingGroupName'], ScalingProcesses=['AZRebalance'])
cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, "CustomResourcePhysicalID")
except BaseException as err:
print('ERROR: ', err)
cfnresponse.send(event, context, cfnresponse.FAILED, {}, "CustomResourcePhysicalID")
Handler: index.handler
Role: !GetAtt AsgProcessSuspenderRole.Arn
Runtime: 'python3.7'

AzRebalancingSuspender:
Type: AWS::CloudFormation::CustomResource
Version: 1.0
Properties:
ServiceToken: !GetAtt AzRebalancingSuspenderFunction.Arn
AutoScalingGroupName: !Ref AgentAutoScaleGroup

SecurityGroup:
Type: AWS::EC2::SecurityGroup
Condition: CreateSecurityGroup
Expand Down

0 comments on commit cc93588

Please sign in to comment.