-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudformation.yaml
308 lines (308 loc) · 9.75 KB
/
cloudformation.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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
---
AWSTemplateFormatVersion: '2010-09-09'
Description: "Setup pre-requisites"
Parameters:
DataLakeRawIoTAChannelS3Bucket:
Description: "S3 bucket for IoT Analytics Channel"
Type: String
Default: "akr-datalake-raw-iota-channel"
DataLakeSilverIoTADatastoreS3Bucket:
Description: "S3 bucket for IoT Analytics Data store"
Type: String
Default: "akr-datalake-silver-iota-datastore"
DataLakeGoldIoTADatasetS3Bucket:
Description: "S3 bucket for IoT Analytics Data set"
Type: String
Default: "akr-datalake-gold-iota-dataset"
DataLakeGoldS3Bucket:
Description: "S3 bucket in your existing data lake"
Type: String
Default: "akr-datalake-gold"
IoTAGlueDB:
Description: "Glue DB to host metadata for the IoT Analytics dataset written to S3"
Type: String
Default: "akr_datalake_iota_glue_db"
IoTAGlueTable:
Description: "Glue table to write the necessary schema/metadata of the IoT Analytics dataset content written to S3 for Athena to query"
Type: String
Default: "akr_device_telemetry_stats"
DataLakeGoldGlueDB:
Description: "Glue DB to host metadata for the device specs table"
Type: String
Default: "akr_datalake_gold_glue_db"
DataLakeGoldDeviceSpecsGlueTable:
Description: "Glue catalog table to point to the device specification file on S3 (your existing data lake)"
Type: String
Default: "akr_device_specs"
Resources:
CreateRawBucket:
Type: AWS::S3::Bucket
Properties:
BucketName:
Ref: DataLakeRawIoTAChannelS3Bucket
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
CreateSilverBucket:
Type: AWS::S3::Bucket
Properties:
BucketName:
Ref: DataLakeSilverIoTADatastoreS3Bucket
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
CreateGoldBucket:
Type: AWS::S3::Bucket
Properties:
BucketName:
Ref: DataLakeGoldIoTADatasetS3Bucket
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
CreateDataLakeGoldBucket:
Type: AWS::S3::Bucket
Properties:
BucketName:
Ref: DataLakeGoldS3Bucket
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
DataLakeSilverIoTADatastoreBucketPolicy:
Type: AWS::S3::BucketPolicy
DependsOn: CreateSilverBucket
Properties:
Bucket:
Ref: DataLakeSilverIoTADatastoreS3Bucket
PolicyDocument:
Statement:
-
Principal:
Service:
- iotanalytics.amazonaws.com
Action:
- "s3:GetBucketLocation"
- "s3:GetObject"
- "s3:ListBucket"
- "s3:ListBucketMultipartUploads"
- "s3:ListMultipartUploadParts"
- "s3:AbortMultipartUpload"
- "s3:PutObject"
Effect: "Allow"
Resource:
- Fn::Join:
- ""
- - 'arn:aws:s3:::'
- Ref: DataLakeSilverIoTADatastoreS3Bucket
- Fn::Join:
- ""
- - 'arn:aws:s3:::'
- Ref: DataLakeSilverIoTADatastoreS3Bucket
- '/*'
DemoIoTACMSBIAMRole:
Type: AWS::IAM::Role
Properties:
"RoleName": "iota_cmsb_role"
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- iot.amazonaws.com
- iotanalytics.amazonaws.com
- glue.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSGlueConsoleFullAccess
- arn:aws:iam::aws:policy/service-role/AWSGlueServiceRole
Policies:
- PolicyName: "iota_batchputmessage_policy"
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: "Allow"
Action: "iotanalytics:BatchPutMessage"
Resource: "*"
- PolicyName: "demo_iota_s3_readwrite_policy"
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: "Allow"
Action:
- "s3:PutObject"
- "s3:GetObject"
- "s3:ListBucket"
Resource:
- Fn::Join:
- ""
- - 'arn:aws:s3:::'
- Ref: DataLakeRawIoTAChannelS3Bucket
- Fn::Join:
- ""
- - 'arn:aws:s3:::'
- Ref: DataLakeRawIoTAChannelS3Bucket
- '/*'
- Fn::Join:
- ""
- - 'arn:aws:s3:::'
- Ref: DataLakeSilverIoTADatastoreS3Bucket
- Fn::Join:
- ""
- - 'arn:aws:s3:::'
- Ref: DataLakeSilverIoTADatastoreS3Bucket
- '/*'
- Fn::Join:
- ""
- - 'arn:aws:s3:::'
- Ref: DataLakeGoldIoTADatasetS3Bucket
- Fn::Join:
- ""
- - 'arn:aws:s3:::'
- Ref: DataLakeGoldIoTADatasetS3Bucket
- '/*'
CreateIoTAGlueDB:
Type: AWS::Glue::Database
Properties:
CatalogId:
Ref: AWS::AccountId
DatabaseInput:
Name:
Ref: IoTAGlueDB
CreateIoTAGlueTable:
Type: AWS::Glue::Table
DependsOn: CreateIoTAGlueDB
Properties:
CatalogId:
Ref: AWS::AccountId
DatabaseName:
Ref: IoTAGlueDB
TableInput:
Name:
Ref: IoTAGlueTable
StorageDescriptor:
Columns:
- Name: "dtts"
Type: "string"
- Name: "deviceid"
Type: "string"
- Name: "avg_temp"
Type: "string"
- Name: "avg_flow"
Type: "string"
- Name: "avg_humidity"
Type: "string"
- Name: "avg_vibration"
Type: "string"
Location:
Fn::Join:
- ""
- - 's3://'
- Ref: DataLakeGoldIoTADatasetS3Bucket
- '/'
- Ref: IoTAGlueDB
- '/'
- Ref: IoTAGlueTable
InputFormat: "org.apache.hadoop.mapred.TextInputFormat"
OutputFormat: "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat"
Compressed: false
SerdeInfo:
SerializationLibrary: "org.apache.hadoop.hive.serde2.OpenCSVSerde"
Parameters:
separatorChar: ","
Parameters:
classification: "csv"
skip.header.line.count: "1"
CreateDataLakeGoldGlueDB:
Type: AWS::Glue::Database
Properties:
CatalogId:
Ref: AWS::AccountId
DatabaseInput:
Name:
Ref: DataLakeGoldGlueDB
CreateDataLakeGoldDeviceSpecsGlueTable:
Type: AWS::Glue::Table
DependsOn: CreateDataLakeGoldGlueDB
Properties:
CatalogId:
Ref: AWS::AccountId
DatabaseName:
Ref: DataLakeGoldGlueDB
TableInput:
Name:
Ref: DataLakeGoldDeviceSpecsGlueTable
StorageDescriptor:
Columns:
- Name: "deviceid"
Type: "string"
- Name: "manufacturer"
Type: "string"
- Name: "weight"
Type: "string"
- Name: "battery"
Type: "string"
- Name: "battery_life"
Type: "string"
- Name: "min_temp_c"
Type: "bigint"
- Name: "max_temp_c"
Type: "bigint"
- Name: "min_humidity"
Type: "bigint"
- Name: "max_humidity"
Type: "bigint"
Location:
Fn::Join:
- ""
- - 's3://'
- Ref: DataLakeGoldS3Bucket
- '/'
- Ref: DataLakeGoldGlueDB
- '/'
- Ref: DataLakeGoldDeviceSpecsGlueTable
InputFormat: "org.apache.hadoop.mapred.TextInputFormat"
OutputFormat: "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat"
Compressed: false
SerdeInfo:
SerializationLibrary: "org.apache.hadoop.hive.serde2.OpenCSVSerde"
Parameters:
separatorChar: ","
quoteChar: "\""
Parameters:
classification: "csv"
skip.header.line.count: "1"
Outputs:
DemoIoTACMSBIAMRoleArn:
Description: "Execution role for the random string generator for Redshift master user password"
Value:
Fn::GetAtt:
- DemoIoTACMSBIAMRole
- Arn
Export:
Name:
Fn::Sub: "${AWS::StackName}-DemoIoTACMSBIAMRoleArn"