@@ -1118,3 +1118,65 @@ Resources:
1118
1118
ScaleOutFactor : !Ref ScaleOutFactor
1119
1119
ScaleOutForWaitingJobs : !Ref ScaleOutForWaitingJobs
1120
1120
DisableScaleIn : " false"
1121
+
1122
+ LifecycleHookLambdaRole :
1123
+ Type : AWS::IAM::Role
1124
+ Properties :
1125
+ Path : /
1126
+ AssumeRolePolicyDocument :
1127
+ Statement :
1128
+ - Effect : Allow
1129
+ Principal :
1130
+ Service : lambda.amazonaws.com
1131
+ Action : sts:AssumeRole
1132
+ ManagedPolicyArns :
1133
+ - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
1134
+ Policies :
1135
+ - PolicyName : CompleteLifecycleAction
1136
+ PolicyDocument :
1137
+ Version : ' 2012-10-17'
1138
+ Statement :
1139
+ - Effect : Allow
1140
+ Action : autoscaling:CompleteLifecycleAction
1141
+ Resource : !Sub arn:${AWS::Partition}:autoscaling:${AWS::Region}:${AWS::AccountId}:autoScalingGroup:*:autoScalingGroupName/${AWS::StackName}-AgentAutoScaleGroup-*
1142
+
1143
+ BootHook :
1144
+ Type : AWS::AutoScaling::LifecycleHook
1145
+ Properties :
1146
+ AutoScalingGroupName : !Ref AgentAutoScaleGroup
1147
+ LifecycleHookName : BootHook
1148
+ LifecycleTransition : autoscaling:EC2_INSTANCE_LAUNCHING
1149
+ # We give instances five minutes to respond to this hook else we abandon
1150
+ # them
1151
+ HeartbeatTimeout : 300
1152
+
1153
+ BootHookFunction :
1154
+ Type : AWS::Lambda::Function
1155
+ Properties :
1156
+ Description : ' Launch Buildkite Agent on Auto Scaling group instance'
1157
+ Code :
1158
+ ZipFile : |
1159
+
1160
+ Handler : index.handler
1161
+ Role : !GetAtt LifecycleHookLambdaRole.Arn
1162
+ Runtime : ' nodejs14.x'
1163
+
1164
+ ShutdownHook :
1165
+ Type : AWS::AutoScaling::LifecycleHook
1166
+ Properties :
1167
+ AutoScalingGroupName : !Ref AgentAutoScaleGroup
1168
+ LifecycleHookName : ShutdownHook
1169
+ LifecycleTransition : autoscaling:EC2_INSTANCE_TERMINATING
1170
+ # We give instances one hour to respond to this hook else we abandon them
1171
+ HeartbeatTimeout : 3600
1172
+
1173
+ ShutdownHookFunction :
1174
+ Type : AWS::Lambda::Function
1175
+ Properties :
1176
+ Description : ' Terminate Buildkite Agent on Auto Scaling group instance'
1177
+ Code :
1178
+ ZipFile : |
1179
+
1180
+ Handler : index.handler
1181
+ Role : !GetAtt LifecycleHookLambdaRole.Arn
1182
+ Runtime : ' nodejs14.x'
0 commit comments