Skip to content

Commit ba2fd09

Browse files
committed
Add an SSM role and boot hook automation
1 parent 921301a commit ba2fd09

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

templates/aws-stack.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,72 @@ Resources:
11301130
# them
11311131
HeartbeatTimeout: 300
11321132

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+
11331199
ShutdownHook:
11341200
Type: AWS::AutoScaling::LifecycleHook
11351201
Properties:

0 commit comments

Comments
 (0)