forked from awslabs/amazon-redshift-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.yaml
294 lines (288 loc) · 11.6 KB
/
deploy.yaml
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
-
Label:
default: Configuration
Parameters:
- S3ConfigPath
- SecurityGroups
- SubnetIds
- WlmSchedulerConfigLocation
-
Label:
default: Run Schedule Cron Expressions
Parameters:
- ColumnEncodingCronExpression
- MonitorCronExpression
- AnalyzeCronExpression
- VacuumCronExpression
- SysTablesCronExpression
- WlmSchedulerCronExpression
ParameterLabels:
S3ConfigPath:
default: S3 Config File
SecurityGroups:
default: VPC Security Group ID
SubnetIds:
default: VPC Subnet ID's for Networking
ColumnEncodingCronExpression:
default: Column Encoding
MonitorCronExpression:
default: Enhanced Monitoring
AnalyzeCronExpression:
default: Table Statistics Analysis
VacuumCronExpression:
default: Table Vacuum
SysTablesCronExpression:
default: System Tables Persistence
WlmSchedulerCronExpression:
default: WLM Scheduler
WlmSchedulerConfigLocation:
default: WLM Scheduler Configuration
Parameters:
S3ConfigPath:
Default: s3://my-bucket/prefix/config-file.json
Description: Configuration File for this Utility instance
Type: String
AllowedPattern: ^s3:\/\/([A-z0-9\-]+)\/(.*)$
SecurityGroups:
Default: mygroup1, mygroup2
Description: Security Groups as CSV list to use for the deployed function (may be required for Redshift security policy)
Type: CommaDelimitedList
SubnetIds:
Default: subnet1, subnet2, subnet3
Description: List of private Subnets in VPC in which the function will egress network connections
Type: CommaDelimitedList
ColumnEncodingCronExpression:
Default: 0 0 * * ? *
Description: Cron expression for when to run the Column Encoding Utility (default midnight daily)
Type: String
AllowedPattern: ^([0-5]?[0-9]|\*|\,|\-|\/) ([ 01]?[0-9]|2[0-3]|\*|\,|\-|\/) ([ 012]?[1-9]|3[01]|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|\*|\,|\-|\/|\?|L|W) ([0]?[1-9]|1[0-2]|\*|\,|\-|\/) ([1-7]|MON|TUE|WED|THU|FRI|SAT|SUN|\*|\,|\-|\/|\?|L|\#) (19[7-9][0-9]|2[01][0-9][0-9]|\*|\,|\-|\/)$
AnalyzeCronExpression:
Default: 0 1 * * ? *
Description: Cron expression for when to run the Analyze Utility (default 1 am daily)
Type: String
AllowedPattern: ^([0-5]?[0-9]|\*|\,|\-|\/) ([ 01]?[0-9]|2[0-3]|\*|\,|\-|\/) ([ 012]?[1-9]|3[01]|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|\*|\,|\-|\/|\?|L|W) ([0]?[1-9]|1[0-2]|\*|\,|\-|\/) ([1-7]|MON|TUE|WED|THU|FRI|SAT|SUN|\*|\,|\-|\/|\?|L|\#) (19[7-9][0-9]|2[01][0-9][0-9]|\*|\,|\-|\/)$
VacuumCronExpression:
Default: 0 2 * * ? *
Description: Cron expression for when to run the Vacuum Utility (default 2 am daily)
Type: String
AllowedPattern: ^([0-5]?[0-9]|\*|\,|\-|\/) ([ 01]?[0-9]|2[0-3]|\*|\,|\-|\/) ([ 012]?[1-9]|3[01]|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|\*|\,|\-|\/|\?|L|W) ([0]?[1-9]|1[0-2]|\*|\,|\-|\/) ([1-7]|MON|TUE|WED|THU|FRI|SAT|SUN|\*|\,|\-|\/|\?|L|\#) (19[7-9][0-9]|2[01][0-9][0-9]|\*|\,|\-|\/)$
MonitorCronExpression:
Default: 5 * * * ? *
Description: Cron expression for when to run Monitoring (default 5 minutes past every hour)
Type: String
AllowedPattern: ^([0-5]?[0-9]|\*|\,|\-|\/) ([ 01]?[0-9]|2[0-3]|\*|\,|\-|\/) ([ 012]?[1-9]|3[01]|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|\*|\,|\-|\/|\?|L|W) ([0]?[1-9]|1[0-2]|\*|\,|\-|\/) ([1-7]|MON|TUE|WED|THU|FRI|SAT|SUN|\*|\,|\-|\/|\?|L|\#) (19[7-9][0-9]|2[01][0-9][0-9]|\*|\,|\-|\/)$
SysTablesCronExpression:
Default: 0 0 * * ? *
Description: Cron expression for when to run System Table Persistence (nightly at midnight)
Type: String
AllowedPattern: ^([0-5]?[0-9]|\*|\,|\-|\/) ([ 01]?[0-9]|2[0-3]|\*|\,|\-|\/) ([ 012]?[1-9]|3[01]|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|\*|\,|\-|\/|\?|L|W) ([0]?[1-9]|1[0-2]|\*|\,|\-|\/) ([1-7]|MON|TUE|WED|THU|FRI|SAT|SUN|\*|\,|\-|\/|\?|L|\#) (19[7-9][0-9]|2[01][0-9][0-9]|\*|\,|\-|\/)$
WlmSchedulerCronExpression:
Default: 2 * * * ? *
Description: Cron expression for when to run the WLM Scheduler Daemon (2 minutes past every hour)
Type: String
AllowedPattern: ^([0-5]?[0-9]|\*|\,|\-|\/) ([ 01]?[0-9]|2[0-3]|\*|\,|\-|\/) ([ 012]?[1-9]|3[01]|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|\*|\,|\-|\/|\?|L|W) ([0]?[1-9]|1[0-2]|\*|\,|\-|\/) ([1-7]|MON|TUE|WED|THU|FRI|SAT|SUN|\*|\,|\-|\/|\?|L|\#) (19[7-9][0-9]|2[01][0-9][0-9]|\*|\,|\-|\/)$
WlmSchedulerConfigLocation:
Default: s3://mybucket/prefix/config.json
Description: Configuration File Location for the WLM Scheduler
Type: String
AllowedPattern: ^s3:\/\/([A-z0-9\-]+)\/(.*)$
Resources:
LambdaRedshiftAutomation:
Type: AWS::Serverless::Function
Properties:
Handler: lambda_function.event_handler
Runtime: python2.7
CodeUri:
Bucket: !Sub awslabs-code-${AWS::Region}
Key: LambdaRedshiftRunner/lambda-redshift-util-runner-1.4.zip
MemorySize: 192
Timeout: 300
Tags:
Name: LambdaRedshiftRunner
Role: !GetAtt RedshiftAutomationIAMRole.Arn
VpcConfig:
SecurityGroupIds:
!Ref SecurityGroups
SubnetIds:
!Ref SubnetIds
RedshiftAutomationIAMRole:
Type: "AWS::IAM::Role"
Properties:
RoleName: "LambdaRedshiftAutomationRole"
Path: "/"
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Sid: "AllowLambdaServiceToAssumeRole"
Effect: "Allow"
Action:
- "sts:AssumeRole"
Principal:
Service:
- "lambda.amazonaws.com"
Policies:
-
PolicyName: "LambdaRedshiftRunnerPolicy"
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action:
- "s3:GetObject"
- "kms:Decrypt"
- "cloudwatch:PutMetricData"
- "redshift:ModifyClusterParameterGroup"
Resource: "*"
AnalyzeEventRule:
Type: "AWS::Events::Rule"
Properties:
Description: CloudWatch Events Rule to invoke Redshift Automation - Analyze Utility
Name: InvokeLambdaRedshiftRunner-Analyze
ScheduleExpression: !Sub cron(${AnalyzeCronExpression})
State: ENABLED
Targets:
- Arn: !GetAtt LambdaRedshiftAutomation.Arn
Id: RedshiftAnalyze
Input:
!Sub |
{
"ExecuteUtility":"Analyze",
"ConfigLocation":"${S3ConfigPath}"
}
CWEventsInvokeAnalyzePermission:
Type: 'AWS::Lambda::Permission'
Properties:
FunctionName: !GetAtt LambdaRedshiftAutomation.Arn
Action: 'lambda:InvokeFunction'
Principal: events.amazonaws.com
SourceAccount: !Ref 'AWS::AccountId'
SourceArn: !GetAtt AnalyzeEventRule.Arn
VacuumEventRule:
Type: "AWS::Events::Rule"
Properties:
Description: CloudWatch Events Rule to invoke Redshift Automation - Vacuum Utility
Name: InvokeLambdaRedshiftRunner-Vacuum
ScheduleExpression: !Sub cron(${VacuumCronExpression})
State: ENABLED
Targets:
- Arn: !GetAtt LambdaRedshiftAutomation.Arn
Id: RedshiftVacuum
Input:
!Sub |
{
"ExecuteUtility":"Vacuum",
"ConfigLocation":"${S3ConfigPath}"
}
CWEventsInvokeVacuumPermission:
Type: 'AWS::Lambda::Permission'
Properties:
FunctionName: !GetAtt LambdaRedshiftAutomation.Arn
Action: 'lambda:InvokeFunction'
Principal: events.amazonaws.com
SourceAccount: !Ref 'AWS::AccountId'
SourceArn: !GetAtt VacuumEventRule.Arn
ColumnEncodingEventRule:
Type: "AWS::Events::Rule"
Properties:
Description: CloudWatch Events Rule to invoke Redshift Automation - Column Encoding Utility
Name: InvokeLambdaRedshiftRunner-ColumnEncodingUtility
ScheduleExpression: !Sub cron(${ColumnEncodingCronExpression})
State: ENABLED
Targets:
- Arn: !GetAtt LambdaRedshiftAutomation.Arn
Id: RedshiftColumnEncodingUtility
Input:
!Sub |
{
"ExecuteUtility":"ColumnEncodingUtility",
"ConfigLocation":"${S3ConfigPath}"
}
CWEventsInvokeColumnEncodingPermission:
Type: 'AWS::Lambda::Permission'
Properties:
FunctionName: !GetAtt LambdaRedshiftAutomation.Arn
Action: 'lambda:InvokeFunction'
Principal: events.amazonaws.com
SourceAccount: !Ref 'AWS::AccountId'
SourceArn: !GetAtt ColumnEncodingEventRule.Arn
MonitoringEventRule:
Type: "AWS::Events::Rule"
Properties:
Description: CloudWatch Events Rule to invoke Redshift Automation - Redshift Monitoring
Name: InvokeLambdaRedshiftRunner-MonitoringUtility
ScheduleExpression: !Sub cron(${MonitorCronExpression})
State: ENABLED
Targets:
- Arn: !GetAtt LambdaRedshiftAutomation.Arn
Id: RedshiftMonitoringUtility
Input:
!Sub |
{
"ExecuteUtility":"Monitoring",
"ConfigLocation":"${S3ConfigPath}"
}
CWEventsInvokeMonitoringPermission:
Type: 'AWS::Lambda::Permission'
Properties:
FunctionName: !GetAtt LambdaRedshiftAutomation.Arn
Action: 'lambda:InvokeFunction'
Principal: events.amazonaws.com
SourceAccount: !Ref 'AWS::AccountId'
SourceArn: !GetAtt MonitoringEventRule.Arn
SystablesEventRule:
Type: "AWS::Events::Rule"
Properties:
Description: CloudWatch Events Rule to invoke Redshift Automation - System Tables Persistence
Name: InvokeLambdaRedshiftRunner-SystemTablesPersistence
ScheduleExpression: !Sub cron(${SysTablesCronExpression})
State: ENABLED
Targets:
- Arn: !GetAtt LambdaRedshiftAutomation.Arn
Id: SystemTablePersistenceUtility
Input:
!Sub |
{
"ExecuteUtility":"SystemTablePersistence",
"ConfigLocation":"${S3ConfigPath}"
}
CWEventsInvokeSystablesPermission:
Type: 'AWS::Lambda::Permission'
Properties:
FunctionName: !GetAtt LambdaRedshiftAutomation.Arn
Action: 'lambda:InvokeFunction'
Principal: events.amazonaws.com
SourceAccount: !Ref 'AWS::AccountId'
SourceArn: !GetAtt SystablesEventRule.Arn
WlmSchedulerEventRule:
Type: "AWS::Events::Rule"
Properties:
Description: CloudWatch Events Rule to invoke Redshift Automation - WLM Scheduler
Name: InvokeLambdaRedshiftRunner-WlmScheduler
ScheduleExpression: !Sub cron(${WlmSchedulerCronExpression})
State: ENABLED
Targets:
- Arn: !GetAtt LambdaRedshiftAutomation.Arn
Id: WlmScheduler
Input:
!Sub |
{
"ExecuteUtility":"WlmScheduler",
"ConfigLocation":"${WlmSchedulerConfigLocation}"
}
CWEventsInvokeWlmSchedulerPermission:
Type: 'AWS::Lambda::Permission'
Properties:
FunctionName: !GetAtt LambdaRedshiftAutomation.Arn
Action: 'lambda:InvokeFunction'
Principal: events.amazonaws.com
SourceAccount: !Ref 'AWS::AccountId'
SourceArn: !GetAtt WlmSchedulerEventRule.Arn