-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno-slack.yml
155 lines (155 loc) · 5.17 KB
/
no-slack.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
AWSTemplateFormatVersion: '2010-09-09'
Description: ECS on EC2 task rerun if task failed before reaching a container instance.
Resources:
ECSTaskRerunEventBridgeRule:
Type: 'AWS::Events::Rule'
Properties:
Name: ecs-task-rerun-event-rule
EventPattern:
source:
- aws.ecs
detail-type:
- AWS API Call via CloudTrail
detail:
eventSource:
- ecs.amazonaws.com
eventName:
- RunTask
responseElements:
failures:
reason:
- exists: true
requestParameters:
startedBy:
- anything-but: "AWS Step Functions"
State: ENABLED
Targets:
- Arn: !Ref ECSTaskRerunStateMachine
Id: ECSTaskRerunStateMachineTarget
RoleArn: !GetAtt ECSTaskRerunEventBridgeRole.Arn
ECSTaskRerunEventBridgeRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: events.amazonaws.com
Action: 'sts:AssumeRole'
Policies:
- PolicyName: ECSTaskRerunEventBridgePolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'states:StartExecution'
Resource: !Ref ECSTaskRerunStateMachine
ECSTaskRerunStateMachine:
Type: 'AWS::StepFunctions::StateMachine'
Properties:
StateMachineName: ECSTaskRerunStateMachine
DefinitionString:
Fn::Sub: |
{
"Comment": "A state machine that starts an ECS task and retries if failure reason is AGENT.",
"StartAt": "Check Reason",
"States": {
"Check Reason": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.detail.responseElements.failures[0].reason",
"StringEquals": "AGENT",
"Next": "Start ECS Task"
}
],
"Default": "End"
},
"Start ECS Task": {
"Type": "Task",
"Resource": "arn:${AWS::Partition}:states:::ecs:runTask.sync",
"Parameters": {
"Cluster.$": "$.detail.requestParameters.cluster",
"TaskDefinition.$": "$.detail.requestParameters.taskDefinition",
"LaunchType.$": "$.detail.requestParameters.launchType"
},
"Retry": [
{
"ErrorEquals": [
"States.ALL"
],
"IntervalSeconds": 60,
"MaxAttempts": 3,
"BackoffRate": 1
}
],
"End": true
},
"End": {
"Type": "Pass",
"End": true
}
}
}
RoleArn: !GetAtt ECSTaskRerunStepFunctionsRole.Arn
LoggingConfiguration:
Destinations:
- CloudWatchLogsLogGroup:
LogGroupArn: !GetAtt ECSTaskRerunStateMachineLogGroup.Arn
IncludeExecutionData: true
Level: ALL
ECSTaskRerunStateMachineLogGroup:
Type: 'AWS::Logs::LogGroup'
Properties:
LogGroupName: /aws/step-functions/ECSTaskRerunStateMachineLogGroup
RetentionInDays: 14
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
ECSTaskRerunStepFunctionsRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: states.amazonaws.com
Action: 'sts:AssumeRole'
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy'
- 'arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess'
Policies:
- PolicyName: ECSTaskRerunStepFunctionsPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- events:PutTargets
- events:PutRule
- events:DescribeRule
Resource:
- !Sub arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForECSTaskRule
- Effect: Allow
Action:
- "ecs:RunTask"
- "ecs:StopTask"
- "ecs:DescribeTasks"
Resource: "*"
- Effect: Allow
Action:
- "logs:CreateLogDelivery"
- "logs:GetLogDelivery"
- "logs:UpdateLogDelivery"
- "logs:DeleteLogDelivery"
- "logs:ListLogDeliveries"
- "logs:PutResourcePolicy"
- "logs:DescribeResourcePolicies"
- "logs:DescribeLogGroups"
Resource: "*"
- Effect: Allow
Action:
- 'iam:PassRole'
Resource: "*"