AWS::IoT::TopicRule
使用 AWS::IoT::TopicRule
资源声明 AWS IoT 规则。有关使用 AWS IoT 规则的信息,请参阅 AWS IoT 开发人员指南 中的 AWS IoT 规则。
语法
要在 AWS CloudFormation 模板中声明此实体,请使用以下语法:
JSON
{ "Type" : "AWS::IoT::TopicRule", "Properties" : { "RuleName" :
String
, "TopicRulePayload" :TopicRulePayload
} }
YAML
Type: AWS::IoT::TopicRule Properties: RuleName:
String
TopicRulePayload:TopicRulePayload
属性
RuleName
-
规则的名称。
必需:否
类型:字符串
Update requires: Replacement
TopicRulePayload
-
规则负载。
必需:是
Update requires: No interruption
返回值
Ref
在将此资源的逻辑 ID 传递给内部 Ref
函数时,Ref
返回主题规则名称。例如:
{ "Ref": "MyTopicRule" }
对于名为 My-Stack 的堆栈(忽略 - 字符),将返回与以下值类似的值:
MyStackMyTopicRule12ABC3D456EFG
For more information about using the Ref
function, see Ref.
Fn::GetAtt
Fn::GetAtt
内部函数返回此类型的一个指定属性的值。以下为可用属性和示例返回值。
有关使用 Fn::GetAtt
内部函数的更多信息,请参阅 Fn::GetAtt。
示例
以下示例声明 AWS IoT 规则。
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