@@ -1130,6 +1130,72 @@ Resources:
1130
1130
# them
1131
1131
HeartbeatTimeout : 300
1132
1132
1133
+ AutomationRole :
1134
+ Type : AWS::IAM::Role
1135
+ Properties :
1136
+ AssumeRolePolicyDocument :
1137
+ Statement :
1138
+ - Effect : Allow
1139
+ Principal :
1140
+ Service : ssm.amazonaws.com
1141
+ Action : sts:AssumeRole
1142
+ Policies :
1143
+ - PolicyName : RunInstanceShellScripts
1144
+ PolicyDocument :
1145
+ Version : ' 2012-10-17'
1146
+ Statement :
1147
+ - Effect : Allow
1148
+ Action : ssm:SendCommand
1149
+ Resource : !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:document/AWS-RunShellScript
1150
+ - Effect : Allow
1151
+ Action : ssm:SendCommand
1152
+ Resource : !Sub arn:${AWS::Partition}:ec2:${AWS::Region}:${AWS::AccountId}:instance/*
1153
+ - PolicyName : CompleteLifecycleActions
1154
+ PolicyDocument :
1155
+ Version : ' 2012-10-17'
1156
+ Statement :
1157
+ - Effect : Allow
1158
+ Action : autoscaling:CompleteLifecycleAction
1159
+ Resource : !Sub arn:${AWS::Partition}:autoscaling:${AWS::Region}:${AWS::AccountId}:autoScalingGroup:*:autoScalingGroupName/${AWS::StackName}-AgentAutoScaleGroup-*
1160
+
1161
+ BootHookAutomation :
1162
+ Type : AWS::SSM::Document
1163
+ Properties :
1164
+ DocumentType : Automation
1165
+ Content :
1166
+ schemaVersion : " 0.3"
1167
+ assumeRole : !GetAtt AutomationRole.Arn
1168
+ description : Start the buildkite-agent and complete the launch lifecycle action
1169
+ parameters :
1170
+ InstanceId :
1171
+ type : String
1172
+ AutoScalingGroupName :
1173
+ type : String
1174
+ default : !Ref AgentAutoScaleGroup
1175
+ LifecycleHook :
1176
+ type : String
1177
+ default : !Ref BootHook
1178
+ mainSteps :
1179
+ - name : RunCommand
1180
+ action : aws:RunCommand
1181
+ inputs :
1182
+ DocumentName : AWS-RunShellScript
1183
+ InstanceIds :
1184
+ - " {{ InstanceId }}"
1185
+ Parameters :
1186
+ executionTimeout : 300
1187
+ commands :
1188
+ - systemctl start buildkite-agent
1189
+ - name : CompleteLifecycleAction
1190
+ action : aws:executeAwsApi
1191
+ inputs :
1192
+ Service : autoscaling
1193
+ Api : CompleteLifecycleAction
1194
+ AutoScalingGroupName : " {{ AutoScalingGroupName }}"
1195
+ InstanceId : " {{ InstanceId }}"
1196
+ LifecycleActionResult : " CONTINUE"
1197
+ LifecycleHookName : " {{ LifecycleHook }}"
1198
+
1133
1199
ShutdownHook :
1134
1200
Type : AWS::AutoScaling::LifecycleHook
1135
1201
Properties :
0 commit comments