AWS::IoT::TopicRule
Use the AWS::IoT::TopicRule resource to declare an AWS IoT rule.
For information about working with AWS IoT rules, see Rules for AWS IoT in the AWS IoT Developer Guide.
Syntax
JSON
{ "Type": "AWS::IoT::TopicRule", "Properties": { "RuleName":String, "TopicRulePayload":TopicRulePayLoad} }
YAML
Type: AWS::IoT::TopicRule Properties: RuleName:StringTopicRulePayload:TopicRulePayLoad
Properties
RuleName-
The name (the physical ID) of the AWS IoT rule.
Required: No
Type: String
Update requires: Replacement
TopicRulePayload-
The actions associated with the AWS IoT rule.
Required: Yes
Type: TopicRulePayload object
Update requires: No interruption
Return Values
Ref
When you provide the logical ID of this resource to the Ref intrinsic
function, Ref returns the topic rule name. For example:
{ "Ref": "MyTopicRule" }
For a stack named My-Stack (the – character is
omitted), a value similar to the following is
returned:
MyStackMyTopicRule12ABC3D456EFG
For more information about using the Ref function, see Ref.
Fn::GetAtt
Fn::GetAtt returns a value for a specified attribute of this type.
The following are the available attributes and sample return values.
Arn-
The Amazon Resource Name (ARN) of the AWS IoT rule, such as
arn:aws:iot:us-east-2:123456789012:rule/MyIoTRule.
For more information about using Fn::GetAtt, see Fn::GetAtt.
Example
The following example declares an AWS IoT rule.
JSON
{ "AWSTemplateFormatVersion": "2010-09-09", "Resources": { "MyTopicRule": { "Type": "AWS::IoT::TopicRule", "Properties": { "RuleName": { "Ref": "NameParameter" }, "TopicRulePayload": { "RuleDisabled": "true", "Sql": "SELECT temp FROM 'SomeTopic' WHERE temp > 60", "Actions": [{ "S3": { "BucketName": { "Ref": "MyBucket" }, "RoleArn": { "Fn::GetAtt": ["MyRole", "Arn"] }, "Key": "MyKey.txt" } }] } } }, "MyBucket": { "Type": "AWS::S3::Bucket", "Properties": {} }, "MyRole": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Principal": { "Service": [ "iot.amazonaws.com" ] }, "Action": [ "sts:AssumeRole" ] }] } } } }, "Parameters": { "NameParameter": { "Type": "String" } } }
YAML
AWSTemplateFormatVersion: "2010-09-09" Resources: MyTopicRule: Type: AWS::IoT::TopicRule Properties: RuleName: Ref: "NameParameter" TopicRulePayload: RuleDisabled: "true" Sql: >- Select temp FROM 'SomeTopic' WHERE temp > 60 Actions: - S3: BucketName: Ref: "MyBucket" RoleArn: Fn::GetAtt: - "MyRole" - "Arn" Key: "MyKey.txt" MyBucket: Type: AWS::S3::Bucket Properties: MyRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: "2012-10-17" Statement: - Effect: "Allow" Principal: Service: - "iot.amazonaws.com" Action: - "sts:AssumeRole" Parameters: NameParameter: Type: "String"
