@@ -1119,6 +1119,29 @@ Resources:
1119
1119
ScaleOutForWaitingJobs : !Ref ScaleOutForWaitingJobs
1120
1120
DisableScaleIn : " false"
1121
1121
1122
+ EventBridgeRuleRole :
1123
+ Type : AWS::IAM::Role
1124
+ Properties :
1125
+ AssumeRolePolicyDocument :
1126
+ Statement :
1127
+ - Effect : Allow
1128
+ Principal :
1129
+ Service : events.amazonaws.com
1130
+ Action : sts:AssumeRole
1131
+ Policies :
1132
+ - PolicyName : StartSsmAutomation
1133
+ PolicyDocument :
1134
+ Version : ' 2012-10-17'
1135
+ Statement :
1136
+ - Effect : Allow
1137
+ Action : ssm:StartAutomationExecution
1138
+ Resource :
1139
+ - !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:automation-definition/${BootHookAutomation}:$DEFAULT
1140
+ - !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:automation-definition/${ShutdownHookAutomation}:$DEFAULT
1141
+ - Effect : Allow
1142
+ Action : iam:PassRole
1143
+ Resource : !GetAtt AutomationRole.Arn
1144
+
1122
1145
AutomationRole :
1123
1146
Type : AWS::IAM::Role
1124
1147
Properties :
@@ -1157,6 +1180,26 @@ Resources:
1157
1180
# them
1158
1181
HeartbeatTimeout : 300
1159
1182
1183
+ BootHookRule :
1184
+ Type : AWS::Events::Rule
1185
+ Properties :
1186
+ Description : !Sub Run the boot time AWS SSM Automation for ${BootHook}
1187
+ EventPattern :
1188
+ source :
1189
+ - aws.autoscaling
1190
+ detail-type :
1191
+ - " EC2 Instance-launch Lifecycle Action"
1192
+ detail :
1193
+ AutoScalingGroupName : !Ref AgentAutoScaleGroup
1194
+ Targets :
1195
+ - Arn : !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:automation-definition/${BootHookAutomation}:$DEFAULT
1196
+ RoleArn : !GetAtt EventBridgeRuleRole.Arn
1197
+ Id : TargetSsmAutomation
1198
+ InputTransformer :
1199
+ InputPathsMap :
1200
+ instanceid : " $.detail.EC2InstanceId"
1201
+ InputTemplate : " {\" InstanceId\" :[<instanceid>]}"
1202
+
1160
1203
BootHookAutomation :
1161
1204
Type : AWS::SSM::Document
1162
1205
Properties :
@@ -1205,6 +1248,26 @@ Resources:
1205
1248
HeartbeatTimeout : 3600
1206
1249
DefaultResult : CONTINUE
1207
1250
1251
+ ShutdownHookRule :
1252
+ Type : AWS::Events::Rule
1253
+ Properties :
1254
+ Description : !Sub Run the shutdown time AWS SSM Automation for ${ShutdownHook}
1255
+ EventPattern :
1256
+ source :
1257
+ - aws.autoscaling
1258
+ detail-type :
1259
+ - " EC2 Instance-terminate Lifecycle Action"
1260
+ detail :
1261
+ AutoScalingGroupName : !Ref AgentAutoScaleGroup
1262
+ Targets :
1263
+ - Arn : !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:automation-definition/${BootHookAutomation}:$DEFAULT
1264
+ RoleArn : !GetAtt EventBridgeRuleRole.Arn
1265
+ Id : TargetSsmAutomation
1266
+ InputTransformer :
1267
+ InputPathsMap :
1268
+ instanceid : " $.detail.EC2InstanceId"
1269
+ InputTemplate : " {\" InstanceId\" :[<instanceid>]}"
1270
+
1208
1271
ShutdownHookAutomation :
1209
1272
Type : AWS::SSM::Document
1210
1273
Properties :
0 commit comments