AWS CloudFormation
User Guide (API Version 2010-05-15)
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。请点击 Amazon AWS 入门,可查看中国地区的具体差异

AWS::IoT::TopicRule

使用 AWS::IoT::TopicRule 资源声明 AWS IoT 规则。

有关使用 AWS IoT 规则的信息,请参阅 AWS IoT 开发人员指南 中的 AWS IoT 规则

语法

JSON

{ "Type": "AWS::IoT::TopicRule", "Properties": { "RuleName": String, "TopicRulePayload": TopicRulePayLoad } }

YAML

Type: "AWS::IoT::TopicRule" Properties: RuleName: String TopicRulePayload: TopicRulePayLoad

属性

RuleName

AWS IoT 规则的名称(物理 ID)。

Required: No

Type: String

更新要求替换

TopicRulePayload

与 AWS IoT 规则关联的操作。

Required: Yes

类型TopicRulePayload 对象

更新要求无需中断

返回值

Ref

当向 Ref 内部函数提供此资源的逻辑 ID 时,Ref 将返回主题规则名称。例如:

{ "Ref": "MyTopicRule" }

对于名为 My-Stack 的堆栈(忽略 字符),将返回与以下值类似的值:

MyStackMyTopicRule12ABC3D456EFG

有关使用 Ref 功能的更多信息,请参阅参考

Fn::GetAtt

Fn::GetAtt 返回一个此类型指定属性的值。以下为可用属性和示例返回值。

Arn

AWS IoT 规则的 Amazon 资源名称 (ARN),如 arn:aws:iot:us-west-2:123456789012:rule/MyIoTRule

有关使用 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"

本页内容: