diff --git a/packages/@aws-cdk/aws-iot/README.md b/packages/@aws-cdk/aws-iot/README.md index 6a9640629891a..42ab651f26f81 100644 --- a/packages/@aws-cdk/aws-iot/README.md +++ b/packages/@aws-cdk/aws-iot/README.md @@ -59,6 +59,8 @@ const func = new lambda.Function(this, 'MyFunction', { }); new iot.TopicRule(this, 'TopicRule', { + topicRuleName: 'MyTopicRule', // optional + description: 'invokes the lambda finction', // optional sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id, timestamp() as timestamp FROM 'device/+/data'"), actions: [new actions.LambdaFunctionAction(func)], }); @@ -72,3 +74,12 @@ const topicRule = new iot.TopicRule(this, 'TopicRule', { }); topicRule.addAction(new actions.LambdaFunctionAction(func)) ``` + +If you wanna make the topic rule disable, add property `enabled: false` as following: + +```ts +new iot.TopicRule(this, 'TopicRule', { + sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id, timestamp() as timestamp FROM 'device/+/data'"), + enabled: false, +}); +``` diff --git a/packages/@aws-cdk/aws-iot/lib/topic-rule.ts b/packages/@aws-cdk/aws-iot/lib/topic-rule.ts index a8cd21fe2bd96..8860a611e4af3 100644 --- a/packages/@aws-cdk/aws-iot/lib/topic-rule.ts +++ b/packages/@aws-cdk/aws-iot/lib/topic-rule.ts @@ -41,6 +41,20 @@ export interface TopicRuleProps { */ readonly actions?: IAction[]; + /** + * A textual description of the topic rule. + * + * @default None + */ + readonly description?: string; + + /** + * Specifies whether the rule is enabled. + * + * @default true + */ + readonly enabled?: boolean + /** * A simplified SQL syntax to filter messages received on an MQTT topic and push the data elsewhere. * @@ -102,6 +116,8 @@ export class TopicRule extends Resource implements ITopicRule { topicRulePayload: { actions: Lazy.any({ produce: () => this.actions }), awsIotSqlVersion: sqlConfig.awsIotSqlVersion, + description: props.description, + ruleDisabled: props.enabled === undefined ? undefined : !props.enabled, sql: sqlConfig.sql, }, }); diff --git a/packages/@aws-cdk/aws-iot/test/topic-rule.test.ts b/packages/@aws-cdk/aws-iot/test/topic-rule.test.ts index 66246e860dddb..6e4a49c234e60 100644 --- a/packages/@aws-cdk/aws-iot/test/topic-rule.test.ts +++ b/packages/@aws-cdk/aws-iot/test/topic-rule.test.ts @@ -71,6 +71,36 @@ test('can set physical name', () => { }); }); +test('can set description', () => { + const stack = new cdk.Stack(); + + new iot.TopicRule(stack, 'MyTopicRule', { + description: 'test-description', + sql: iot.IotSql.fromStringAsVer20151008("SELECT topic(2) as device_id, temperature FROM 'device/+/data'"), + }); + + Template.fromStack(stack).hasResourceProperties('AWS::IoT::TopicRule', { + TopicRulePayload: { + Description: 'test-description', + }, + }); +}); + +test('can set ruleDisabled', () => { + const stack = new cdk.Stack(); + + new iot.TopicRule(stack, 'MyTopicRule', { + enabled: false, + sql: iot.IotSql.fromStringAsVer20151008("SELECT topic(2) as device_id, temperature FROM 'device/+/data'"), + }); + + Template.fromStack(stack).hasResourceProperties('AWS::IoT::TopicRule', { + TopicRulePayload: { + RuleDisabled: true, + }, + }); +}); + test.each([ ['fromStringAsVer20151008', iot.IotSql.fromStringAsVer20151008, '2015-10-08'], ['fromStringAsVer20160323', iot.IotSql.fromStringAsVer20160323, '2016-03-23'],