Skip to content

Commit 9700a02

Browse files
committed
Add a terminate instance ssm automation
1 parent 9268219 commit 9700a02

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

templates/aws-stack.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,3 +1204,41 @@ Resources:
12041204
# We give instances one hour to respond to this hook else we continue
12051205
HeartbeatTimeout: 3600
12061206
DefaultResult: CONTINUE
1207+
1208+
ShutdownHookAutomation:
1209+
Type: AWS::SSM::Document
1210+
Properties:
1211+
DocumentType: Automation
1212+
Content:
1213+
schemaVersion: "0.3"
1214+
assumeRole: !GetAtt AutomationRole.Arn
1215+
description: Stop the buildkite-agent, wait for it to exit, complete the launch lifecycle action
1216+
parameters:
1217+
InstanceId:
1218+
type: String
1219+
AutoScalingGroupName:
1220+
type: String
1221+
default: !Ref AgentAutoScaleGroup
1222+
LifecycleHook:
1223+
type: String
1224+
default: !Ref ShutdownHook
1225+
mainSteps:
1226+
- name: RunCommand
1227+
action: aws:RunCommand
1228+
inputs:
1229+
DocumentName: AWS-RunShellScript
1230+
InstanceIds:
1231+
- "{{ InstanceId }}"
1232+
Parameters:
1233+
executionTimeout: 3600
1234+
commands:
1235+
- systemctl stop buildkite-agent
1236+
- name: CompleteLifecycleAction
1237+
action: aws:executeAwsApi
1238+
inputs:
1239+
Service: autoscaling
1240+
Api: CompleteLifecycleAction
1241+
AutoScalingGroupName: "{{ AutoScalingGroupName }}"
1242+
InstanceId: "{{ InstanceId }}"
1243+
LifecycleActionResult: "CONTINUE"
1244+
LifecycleHookName: "{{ LifecycleHook }}"

0 commit comments

Comments
 (0)