-
Notifications
You must be signed in to change notification settings - Fork 3
/
template.yaml
229 lines (215 loc) · 6.82 KB
/
template.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
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: >
eventbridge-integration-solution-buildkite-visualization
(qs-1qpmasrtu)
Metadata:
AWS::ServerlessRepo::Application:
Name: Amazon-EventBridge-Integration-Solution-Buildkite-Visualization
Description: This application demonstrates an integration with AWS Lambda, Amazon S3, AWS Glue, and Amazon Athena, for the Buildkite Amazon EventBridge Integration
Author: AWS Quick Start
LicenseUrl: LICENSE
ReadmeUrl: README.md
Labels: ['amazon', 'eventbridge', 'integration', 'solution', 'aws','lambda', 'glue', 'athena', 's3', 'buildkite']
HomePageUrl: https://aws.amazon.com/quickstart/eventbridge/buildkite-visualization/
SemanticVersion: 0.1.3
SourceCodeUrl: https://github.com/aws-quickstart/eventbridge-integration-solution-buildkite-visualization
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Amazon EventBridge Integration Solution
Parameters:
- EventSourceName
- Label:
default: Amazon S3
Parameters:
- BucketName
- Label:
default: AWS Glue
Parameters:
- GlueCrawlerName
- GlueDBName
- GlueTablePrefix
ParameterLabels:
EventSourceName:
default: Event Source Name
BucketName:
default: Bucket Name
GlueCrawlerName:
default: Crawler Name
GlueDBName:
default: DB Name
GlueTablePrefix:
default: Table Prefix
Parameters:
EventSourceName:
Type: String
AllowedPattern: aws\.partner(/[\.\-_A-Za-z0-9]+){2,}
MinLength: 1
MaxLength: 256
Description: Name of the Buildkite Partner Event Source to associate with an Event Bus. For example, aws.partner/buildkite.com/<org-slug>/<uuid>
BucketName:
Type: String
Default: ''
AllowedPattern: '[a-z0-9-]*'
MaxLength: 63
Description: Name of the Amazon S3 Bucket to create. Leave blank for an automatically generated name. Characters are limited to lowercase, numbers, and dashes to accomodate AWS Glue's allowed nomenclature.
GlueCrawlerName:
Type: String
Default: buildkite-crawler
AllowedPattern: '[a-z0-9-]*'
MaxLength: 63
Description: Name of the AWS Glue Crawler to create. Characters are limited to lowercase, numbers, and dashes to accomodate AWS Glue's allowed nomenclature.
GlueDBName:
Type: String
Default: buildkite-db
AllowedPattern: '[a-z0-9-]*'
MaxLength: 63
Description: Name of the AWS Glue DB to create. Characters are limited to lowercase, numbers, and dashes to accomodate AWS Glue's allowed nomenclature.
GlueTablePrefix:
Type: String
Default: crawler_
AllowedPattern: '[a-z0-9_]*'
MinLength: 0
MaxLength: 128
Description: Prefix for the AWS Glue table that's created once you run your crawler. Characters are limited to lowercase, numbers, and underscores to accomodate AWS Glue's allowed nomenclature.
Conditions:
AutoGenerateBucketName:
!Equals [ !Ref BucketName, '' ]
Resources:
EventBridgeEventBus:
Type: AWS::Events::EventBus
Properties:
EventSourceName: !Ref EventSourceName
Name: !Ref EventSourceName
EventBridgeFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/job_finished/
Handler: app.lambda_handler
Runtime: python3.8
Environment:
Variables:
s3_bucket: !Ref S3Bucket
Policies:
- S3WritePolicy:
BucketName: !Ref S3Bucket
Events:
EventBridgeRule:
Type: EventBridgeRule
Properties:
Pattern:
account:
- !Ref AWS::AccountId
detail-type:
- Job Finished
EventBusName: !Ref EventBridgeEventBus
S3Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
BucketName:
!If [ AutoGenerateBucketName, !Ref 'AWS::NoValue', !Ref BucketName ]
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
BuildkiteCrawler:
Type: AWS::Glue::Crawler
Properties:
Name: !Ref GlueCrawlerName
Role: !GetAtt CrawlerRole.Arn
DatabaseName: !Ref BuildkiteDB
Classifiers:
- !Ref JsonClassifier
TablePrefix: !Ref GlueTablePrefix
Targets:
S3Targets:
- Path: !Ref S3Bucket
BuildkiteDB:
Type: AWS::Glue::Database
Properties:
CatalogId: !Ref AWS::AccountId
DatabaseInput:
Name: !Ref GlueDBName
Description: Database with a table that contains job-finished data
JsonClassifier:
Type: AWS::Glue::Classifier
Properties:
JsonClassifier:
Name: JsonClassifier
JsonPath: "$[*]"
CrawlerRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- glue.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
- PolicyName: "crawler-policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- glue:*
- cloudwatch:PutMetricData
Resource:
- "*"
- Effect: Allow
Action:
- s3:GetBucketLocation
- s3:ListBucket
- s3:ListAllMyBuckets
- s3:GetBucketAcl
Resource:
- !Sub ${S3Bucket.Arn}
- Effect: Allow
Action:
- s3:GetObject
Resource:
- !Sub ${S3Bucket.Arn}/*
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- arn:aws:logs:*:*:/aws-glue/*
AthenaQuery:
Type: AWS::Athena::NamedQuery
Properties:
Database: !Ref BuildkiteDB
Description: A query that selects all aggregated data
Name: JobFinishedEvents
QueryString: !Sub
- SELECT * FROM ${GlueTablePrefix}${CrawlerTable}
- CrawlerTable: !Join [ '_', !Split [ '-', !Ref S3Bucket ] ]
Outputs:
EventBridgeRule:
Description: EventBridge Rule ARN
Value: !GetAtt EventBridgeFunctionEventBridgeRule.Arn
EventBridgeFunction:
Description: Lambda Function ARN
Value: !GetAtt EventBridgeFunction.Arn
EventBridgeEventBus:
Description: Event Bus ARN
Value: !GetAtt EventBridgeEventBus.Arn
S3Bucket:
Description: S3 Bucket ARN
Value: !GetAtt S3Bucket.Arn
CrawlerRole:
Description: IAM Role Arn for the Glue Crawler
Value: !GetAtt CrawlerRole.Arn