forked from awslabs/amazon-timestream-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding IoT topic rule to CFN template
- Loading branch information
Praneeta
committed
Jun 3, 2021
1 parent
a4a6cb1
commit 2dcce84
Showing
2 changed files
with
160 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,165 @@ | ||
{ | ||
"Description": "AWS IoT Core and Amazon Timestream integration.", | ||
|
||
"Resources": { | ||
"TimestreamDataBase": { | ||
"Type" : "AWS::Timestream::Database" | ||
}, | ||
|
||
"TimestreamTable": { | ||
"Type" : "AWS::Timestream::Table", | ||
"Properties" : { | ||
"DatabaseName" : {"Ref": "TimestreamDataBase"}, | ||
"RetentionProperties" : { | ||
"MemoryStoreRetentionPeriodInHours" : "24", | ||
"MagneticStoreRetentionPeriodInDays" : "5" | ||
} | ||
"TimestreamDataBase": { | ||
"Type": "AWS::Timestream::Database" | ||
}, | ||
"TimestreamTable": { | ||
"Type": "AWS::Timestream::Table", | ||
"Properties": { | ||
"DatabaseName": { | ||
"Ref": "TimestreamDataBase" | ||
}, | ||
"RetentionProperties": { | ||
"MemoryStoreRetentionPeriodInHours": "24", | ||
"MagneticStoreRetentionPeriodInDays": "5" | ||
} | ||
} | ||
}, | ||
"IoTDataRule": { | ||
"Type": "AWS::IoT::TopicRule", | ||
"Properties": { | ||
"TopicRulePayload": { | ||
"RuleDisabled": false, | ||
"Actions": [ | ||
{ | ||
"Timestream": { | ||
"RoleArn": { | ||
"Fn::GetAtt": [ | ||
"IoTDataToTimestreamRole", | ||
"Arn" | ||
] | ||
}, | ||
"DatabaseName": { | ||
"Ref": "TimestreamDataBase" | ||
}, | ||
"TableName": { | ||
"Fn::Select": [ | ||
1, | ||
{ | ||
"Fn::Split": [ | ||
"|", | ||
{ | ||
"Ref": "TimestreamTable" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"Dimensions": [ | ||
{ | ||
"Name": "device_id", | ||
"Value": "${device_id}" | ||
}, | ||
{ | ||
"Name": "building", | ||
"Value": "${building}" | ||
}, | ||
{ | ||
"Name": "room", | ||
"Value": "${room}" | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"Sql": "SELECT humidity, pressure, temperature FROM 'dt/sensor/#'" | ||
} | ||
} | ||
}, | ||
"IoTDataToTimestreamRole": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ | ||
"iot.amazonaws.com" | ||
] | ||
}, | ||
"Action": [ | ||
"sts:AssumeRole" | ||
] | ||
} | ||
] | ||
}, | ||
"Policies": [ | ||
{ | ||
"PolicyName": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"IoTDataToTimestreamInlinePolicy-", | ||
{ | ||
"Ref": "AWS::Region" | ||
} | ||
] | ||
] | ||
}, | ||
"PolicyDocument": { | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"timestream:WriteRecords" | ||
], | ||
"Resource": [ | ||
{ | ||
"Fn::GetAtt": [ | ||
"TimestreamTable", | ||
"Arn" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"timestream:DescribeEndpoints" | ||
], | ||
"Resource": "*" | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"Path": "/service-role/" | ||
} | ||
} | ||
}, | ||
|
||
"IoTDataToTimestreamRole": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ { | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ "iot.amazonaws.com" ] | ||
}, | ||
"Action": [ "sts:AssumeRole" ] | ||
} ] | ||
}, | ||
"Policies": [ { | ||
"PolicyName": {"Fn::Join": ["", ["IoTDataToTimestreamInlinePolicy-", {"Ref": "AWS::Region"} ]]}, | ||
"PolicyDocument": { | ||
"Version":"2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect":"Allow", | ||
"Action": [ | ||
"timestream:WriteRecords" | ||
], | ||
"Resource": [ | ||
{ "Fn::GetAtt": ["TimestreamTable", "Arn"] } | ||
] | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"timestream:DescribeEndpoints" | ||
], | ||
"Resource": "*" | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"Path": "/service-role/" | ||
} | ||
} | ||
}, | ||
|
||
"Outputs" : { | ||
"TimestreamDataBaseName": { | ||
"Description" : "Timestream data base name", | ||
"Value" : { "Ref": "TimestreamDataBase" } | ||
}, | ||
"TimestreamTableName": { | ||
"Description" : "Timestream table name", | ||
"Value" : { "Ref": "TimestreamTable" } | ||
}, | ||
"TimestreamTableArn": { | ||
"Description" : "Timestream table arn", | ||
"Value" : { "Fn::GetAtt": ["TimestreamTable", "Arn"] } | ||
}, | ||
"IoTDataToTimestreamRoleArn": { | ||
"Description": "Arn for the IAM role to allow write to Timestream table", | ||
"Value": { "Fn::GetAtt": ["IoTDataToTimestreamRole", "Arn"] } | ||
} | ||
"Outputs": { | ||
"TimestreamDataBaseName": { | ||
"Description": "Timestream data base name", | ||
"Value": { | ||
"Ref": "TimestreamDataBase" | ||
} | ||
}, | ||
"TimestreamTableName": { | ||
"Description": "Timestream table name", | ||
"Value": { | ||
"Ref": "TimestreamTable" | ||
} | ||
}, | ||
"TimestreamTableArn": { | ||
"Description": "Timestream table arn", | ||
"Value": { | ||
"Fn::GetAtt": [ | ||
"TimestreamTable", | ||
"Arn" | ||
] | ||
} | ||
}, | ||
"IoTDataToTimestreamRoleArn": { | ||
"Description": "Arn for the IAM role to allow write to Timestream table", | ||
"Value": { | ||
"Fn::GetAtt": [ | ||
"IoTDataToTimestreamRole", | ||
"Arn" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |