-
Notifications
You must be signed in to change notification settings - Fork 1
/
cloudformation.yaml
123 lines (123 loc) · 3.61 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
AWSTemplateFormatVersion: '2010-09-09'
Resources:
Thing:
Type: AWS::IoT::Thing
Policy:
Type: AWS::IoT::Policy
Properties:
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- iot:Connect
- iot:Publish
- iot:Subscribe
- iot:Receive
Resource: "*"
Database:
Type: AWS::Timestream::Database
Table:
Type: AWS::Timestream::Table
Properties:
DatabaseName: !Ref "Database"
RetentionProperties:
MemoryStoreRetentionPeriodInHours: !Ref "MemoryRetentionHours"
MagneticStoreRetentionPeriodInDays: !Ref "MagneticRetentionDays"
TopicRule:
Type: AWS::IoT::TopicRule
Properties:
TopicRulePayload:
RuleDisabled: false
Sql: "SELECT co2, tmp, hmd, pm2, wifi FROM 'daq'"
Actions:
- Timestream:
RoleArn: !GetAtt ["TopicRuleRole", "Arn"]
DatabaseName: !Ref "Database"
TableName: !Select [1, !Split ["|", !Ref Table]]
Dimensions:
- Name: device_id
Value: "${device_id}"
- Name: room
Value: "${room}"
TopicRuleRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- iot.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: "DaqIoTDataToTimestreamInlinePolicy"
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- timestream:WriteRecords
Resource: !GetAtt ["Table", "Arn"]
- Effect: Allow
Action:
- timestream:DescribeEndpoints
Resource: "*"
Path: "/service-role/"
QueryRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
AWS: !Ref "AWS::AccountId"
Action:
- sts:AssumeRole
Policies:
- PolicyName: "DaqTimestreamQueryInlinePolicy"
PolicyDocument:
Statement:
- Effect: Allow
Action:
- timestream:DescribeDatabase
- timestream:ListTables
Resource: !GetAtt "Database.Arn"
- Effect: Allow
Action:
- timestream:ListMeasures
- timestream:Select
- timestream:DescribeTable
Resource: !GetAtt "Table.Arn"
- Effect: Allow
Action:
- timestream:DescribeEndpoints
- timestream:ListDatabases
- timestream:SelectValues
Resource: "*"
Parameters:
MemoryRetentionHours:
Type: String
Description: Hours to store timeseries data in memory
Default: "24"
MagneticRetentionDays:
Type: String
Description: Days to store timeseries data in magnetic storage
Default: "3650"
Outputs:
ThingName:
Description: IOT Thing name
Value: !Ref "Thing"
PolicyName:
Description: IOT Policy name
Value: !Ref "Policy"
DatabaseTableName:
Description: Timestream database and table name
Value: !Ref "Table"
QueryRole:
Description: Arn of the role used to query the table
Value: !GetAtt "QueryRole.Arn"
TopicRuleName:
Description: Topic rule name for basic ingest
Value: !Ref "TopicRule"