From 0c2063ec7767c712df259d211572b665b3515ff0 Mon Sep 17 00:00:00 2001 From: yamatatsu Date: Wed, 26 Jan 2022 20:31:43 +0900 Subject: [PATCH 1/4] feat(iot): add Action to republish MQTT messages to another MQTT topic --- packages/@aws-cdk/aws-iot-actions/README.md | 17 +++ .../@aws-cdk/aws-iot-actions/lib/index.ts | 1 + .../lib/iot-republish-action.ts | 72 +++++++++++ .../integ.iot-republish-action.expected.json | 65 ++++++++++ .../test/iot/integ.iot-republish-action.ts | 25 ++++ .../test/iot/iot-republish-action.test.ts | 118 ++++++++++++++++++ ...g.firehose-put-record-action.expected.json | 4 - 7 files changed, 298 insertions(+), 4 deletions(-) create mode 100644 packages/@aws-cdk/aws-iot-actions/lib/iot-republish-action.ts create mode 100644 packages/@aws-cdk/aws-iot-actions/test/iot/integ.iot-republish-action.expected.json create mode 100644 packages/@aws-cdk/aws-iot-actions/test/iot/integ.iot-republish-action.ts create mode 100644 packages/@aws-cdk/aws-iot-actions/test/iot/iot-republish-action.test.ts diff --git a/packages/@aws-cdk/aws-iot-actions/README.md b/packages/@aws-cdk/aws-iot-actions/README.md index be475fe028210..2be7ef62a27d5 100644 --- a/packages/@aws-cdk/aws-iot-actions/README.md +++ b/packages/@aws-cdk/aws-iot-actions/README.md @@ -21,6 +21,7 @@ supported AWS Services. Instances of these classes should be passed to Currently supported are: +- Republish a message to another MQTT topic - Invoke a Lambda function - Put objects to a S3 bucket - Put logs to CloudWatch Logs @@ -30,6 +31,22 @@ Currently supported are: - Put records to Kinesis Data Firehose stream - Send messages to SQS queues +## Republish a message to another MQTT topic + +The code snippet below creates an AWS IoT Rule that republish a message to +another MQTT topic when it is triggered. + +```ts +new iot.TopicRule(this, 'TopicRule', { + sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id, timestamp() as timestamp, temperature FROM 'device/+/data'"), + actions: [ + new actions.IotRepublishAction('${topic()}/republish', { + qos: actions.MqttQos.AT_LEAST_ONCE, // optional property, default is MqttQos.ZERO_OR_MORE_TIMES + }), + ], +}); +``` + ## Invoke a Lambda function The code snippet below creates an AWS IoT Rule that invoke a Lambda function diff --git a/packages/@aws-cdk/aws-iot-actions/lib/index.ts b/packages/@aws-cdk/aws-iot-actions/lib/index.ts index a0ee864a5bce2..c3a7bb547b1c8 100644 --- a/packages/@aws-cdk/aws-iot-actions/lib/index.ts +++ b/packages/@aws-cdk/aws-iot-actions/lib/index.ts @@ -3,6 +3,7 @@ export * from './cloudwatch-put-metric-action'; export * from './cloudwatch-set-alarm-state-action'; export * from './common-action-props'; export * from './firehose-put-record-action'; +export * from './iot-republish-action'; export * from './kinesis-put-record-action'; export * from './lambda-function-action'; export * from './s3-put-object-action'; diff --git a/packages/@aws-cdk/aws-iot-actions/lib/iot-republish-action.ts b/packages/@aws-cdk/aws-iot-actions/lib/iot-republish-action.ts new file mode 100644 index 0000000000000..ee7325e06bd3a --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions/lib/iot-republish-action.ts @@ -0,0 +1,72 @@ +import * as iam from '@aws-cdk/aws-iam'; +import * as iot from '@aws-cdk/aws-iot'; +import { CommonActionProps } from './common-action-props'; +import { singletonActionRole } from './private/role'; + +/** + * MQTT Quality of Service + * + * @see https://docs.aws.amazon.com/iot/latest/developerguide/mqtt.html#mqtt-qos + */ +export enum MqttQos { + /** + * QoS level 0. Sent zero or more times. + * This level should be used for messages that are sent over reliable communication links or that can be missed without a problem. + */ + ZERO_OR_MORE_TIMES, + + /** + * QoS level 1. Sent at least one time, and then repeatedly until a PUBACK response is received. + * The message is not considered complete until the sender receives a PUBACK response to indicate successful delivery. + */ + AT_LEAST_ONCE, +} + +/** + * Configuration properties of an action to republish MQTT messages. + */ +export interface IotRepublishActionProps extends CommonActionProps { + /** + * The Quality of Service (QoS) level to use when republishing messages. + * + * @see https://docs.aws.amazon.com/iot/latest/developerguide/mqtt.html#mqtt-qos + * + * @default MqttQos.ZERO_OR_MORE_TIMES + */ + readonly qos?: MqttQos; +} + +/** + * The action to put the record from an MQTT message to republish another MQTT topic. + */ +export class IotRepublishAction implements iot.IAction { + private readonly qos?: MqttQos; + private readonly role?: iam.IRole; + + /** + * @param topic The MQTT topic to which to republish the message. + * @param props Optional properties to not use default + */ + constructor(private readonly topic: string, props: IotRepublishActionProps = {}) { + this.qos = props.qos; + this.role = props.role; + } + + bind(rule: iot.ITopicRule): iot.ActionConfig { + const role = this.role ?? singletonActionRole(rule); + role.addToPrincipalPolicy(new iam.PolicyStatement({ + actions: ['iot:Publish'], + resources: ['*'], + })); + + return { + configuration: { + republish: { + topic: this.topic, + qos: this.qos, + roleArn: role.roleArn, + }, + }, + }; + } +} diff --git a/packages/@aws-cdk/aws-iot-actions/test/iot/integ.iot-republish-action.expected.json b/packages/@aws-cdk/aws-iot-actions/test/iot/integ.iot-republish-action.expected.json new file mode 100644 index 0000000000000..c396017676ac4 --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions/test/iot/integ.iot-republish-action.expected.json @@ -0,0 +1,65 @@ +{ + "Resources": { + "TopicRule40A4EA44": { + "Type": "AWS::IoT::TopicRule", + "Properties": { + "TopicRulePayload": { + "Actions": [ + { + "Republish": { + "Qos": 1, + "RoleArn": { + "Fn::GetAtt": [ + "TopicRuleTopicRuleActionRole246C4F77", + "Arn" + ] + }, + "Topic": "${topic()}/republish" + } + } + ], + "AwsIotSqlVersion": "2016-03-23", + "Sql": "SELECT * FROM 'device/+/data'" + } + } + }, + "TopicRuleTopicRuleActionRole246C4F77": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "iot.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "TopicRuleTopicRuleActionRoleDefaultPolicy99ADD687": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "iot:Publish", + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "TopicRuleTopicRuleActionRoleDefaultPolicy99ADD687", + "Roles": [ + { + "Ref": "TopicRuleTopicRuleActionRole246C4F77" + } + ] + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions/test/iot/integ.iot-republish-action.ts b/packages/@aws-cdk/aws-iot-actions/test/iot/integ.iot-republish-action.ts new file mode 100644 index 0000000000000..762be15e487d1 --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions/test/iot/integ.iot-republish-action.ts @@ -0,0 +1,25 @@ +import * as iot from '@aws-cdk/aws-iot'; +import * as cdk from '@aws-cdk/core'; +import * as actions from '../../lib'; + +class TestStack extends cdk.Stack { + constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { + super(scope, id, props); + + const topicRule = new iot.TopicRule(this, 'TopicRule', { + sql: iot.IotSql.fromStringAsVer20160323( + "SELECT * FROM 'device/+/data'", + ), + }); + + topicRule.addAction( + new actions.IotRepublishAction('${topic()}/republish', { + qos: actions.MqttQos.AT_LEAST_ONCE, + }), + ); + } +} + +const app = new cdk.App(); +new TestStack(app, 'iot-republish-action-test-stack'); +app.synth(); diff --git a/packages/@aws-cdk/aws-iot-actions/test/iot/iot-republish-action.test.ts b/packages/@aws-cdk/aws-iot-actions/test/iot/iot-republish-action.test.ts new file mode 100644 index 0000000000000..c38404a490e54 --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions/test/iot/iot-republish-action.test.ts @@ -0,0 +1,118 @@ +import { Template, Match } from '@aws-cdk/assertions'; +import * as iam from '@aws-cdk/aws-iam'; +import * as iot from '@aws-cdk/aws-iot'; +import * as cdk from '@aws-cdk/core'; +import * as actions from '../../lib'; + +let stack:cdk.Stack; +beforeEach(() => { + stack = new cdk.Stack(); +}); + +test('Default IoT republish action', () => { + // GIVEN + const topicRule = new iot.TopicRule(stack, 'MyTopicRule', { + sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id FROM 'device/+/data'"), + }); + + // WHEN + topicRule.addAction( + new actions.IotRepublishAction('test-topic'), + ); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::IoT::TopicRule', { + TopicRulePayload: { + Actions: [ + { + Republish: { + Topic: 'test-topic', + RoleArn: { + 'Fn::GetAtt': ['MyTopicRuleTopicRuleActionRoleCE2D05DA', 'Arn'], + }, + }, + }, + ], + }, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { + AssumeRolePolicyDocument: { + Statement: [ + { + Action: 'sts:AssumeRole', + Effect: 'Allow', + Principal: { + Service: 'iot.amazonaws.com', + }, + }, + ], + Version: '2012-10-17', + }, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { + PolicyDocument: { + Statement: [ + { + Action: 'iot:Publish', + Effect: 'Allow', + Resource: '*', + }, + ], + Version: '2012-10-17', + }, + PolicyName: 'MyTopicRuleTopicRuleActionRoleDefaultPolicy54A701F7', + Roles: [ + { Ref: 'MyTopicRuleTopicRuleActionRoleCE2D05DA' }, + ], + }); +}); + +test('can set qos', () => { + // GIVEN + const topicRule = new iot.TopicRule(stack, 'MyTopicRule', { + sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id FROM 'device/+/data'"), + }); + + // WHEN + topicRule.addAction( + new actions.IotRepublishAction('test-topic', { qos: actions.MqttQos.AT_LEAST_ONCE }), + ); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::IoT::TopicRule', { + TopicRulePayload: { + Actions: [ + Match.objectLike({ Republish: { Qos: 1 } }), + ], + }, + }); +}); + +test('can set role', () => { + // GIVEN + const topicRule = new iot.TopicRule(stack, 'MyTopicRule', { + sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id FROM 'device/+/data'"), + }); + const role = iam.Role.fromRoleArn(stack, 'MyRole', 'arn:aws:iam::123456789012:role/ForTest'); + + // WHEN + topicRule.addAction( + new actions.IotRepublishAction('test-topic', { role }), + ); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::IoT::TopicRule', { + TopicRulePayload: { + Actions: [ + Match.objectLike({ Republish: { RoleArn: 'arn:aws:iam::123456789012:role/ForTest' } }), + ], + }, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { + PolicyName: 'MyRolePolicy64AB00A5', + Roles: ['ForTest'], + }); +}); diff --git a/packages/@aws-cdk/aws-iot-actions/test/kinesis-firehose/integ.firehose-put-record-action.expected.json b/packages/@aws-cdk/aws-iot-actions/test/kinesis-firehose/integ.firehose-put-record-action.expected.json index 5c484ba7f5049..d1565669b5c04 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/kinesis-firehose/integ.firehose-put-record-action.expected.json +++ b/packages/@aws-cdk/aws-iot-actions/test/kinesis-firehose/integ.firehose-put-record-action.expected.json @@ -123,10 +123,6 @@ "s3:List*", "s3:DeleteObject*", "s3:PutObject", - "s3:PutObjectLegalHold", - "s3:PutObjectRetention", - "s3:PutObjectTagging", - "s3:PutObjectVersionTagging", "s3:Abort*" ], "Effect": "Allow", From 4bf88c82fad1541985058d5fda1af9d2914eef0a Mon Sep 17 00:00:00 2001 From: yamatatsu Date: Thu, 27 Jan 2022 18:09:32 +0900 Subject: [PATCH 2/4] fix snapthot --- .../integ.firehose-put-record-action.expected.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/@aws-cdk/aws-iot-actions/test/kinesis-firehose/integ.firehose-put-record-action.expected.json b/packages/@aws-cdk/aws-iot-actions/test/kinesis-firehose/integ.firehose-put-record-action.expected.json index d1565669b5c04..5c484ba7f5049 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/kinesis-firehose/integ.firehose-put-record-action.expected.json +++ b/packages/@aws-cdk/aws-iot-actions/test/kinesis-firehose/integ.firehose-put-record-action.expected.json @@ -123,6 +123,10 @@ "s3:List*", "s3:DeleteObject*", "s3:PutObject", + "s3:PutObjectLegalHold", + "s3:PutObjectRetention", + "s3:PutObjectTagging", + "s3:PutObjectVersionTagging", "s3:Abort*" ], "Effect": "Allow", From 8c5aaa686ee074cc707ea6ee8e35e0847c10b1d7 Mon Sep 17 00:00:00 2001 From: yamatatsu Date: Thu, 27 Jan 2022 19:47:00 +0900 Subject: [PATCH 3/4] address comments --- packages/@aws-cdk/aws-iot-actions/README.md | 4 +-- .../lib/iot-republish-action.ts | 18 ++++++------ .../test/iot/integ.iot-republish-action.ts | 4 +-- .../test/iot/iot-republish-action.test.ts | 29 ++++++------------- 4 files changed, 22 insertions(+), 33 deletions(-) diff --git a/packages/@aws-cdk/aws-iot-actions/README.md b/packages/@aws-cdk/aws-iot-actions/README.md index 2be7ef62a27d5..9350408859996 100644 --- a/packages/@aws-cdk/aws-iot-actions/README.md +++ b/packages/@aws-cdk/aws-iot-actions/README.md @@ -40,8 +40,8 @@ another MQTT topic when it is triggered. new iot.TopicRule(this, 'TopicRule', { sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id, timestamp() as timestamp, temperature FROM 'device/+/data'"), actions: [ - new actions.IotRepublishAction('${topic()}/republish', { - qos: actions.MqttQos.AT_LEAST_ONCE, // optional property, default is MqttQos.ZERO_OR_MORE_TIMES + new actions.IotRepublishMqttAction('${topic()}/republish', { + qos: actions.MqttQualityOfService.AT_LEAST_ONCE, // optional property, default is MqttQualityOfService.ZERO_OR_MORE_TIMES }), ], }); diff --git a/packages/@aws-cdk/aws-iot-actions/lib/iot-republish-action.ts b/packages/@aws-cdk/aws-iot-actions/lib/iot-republish-action.ts index ee7325e06bd3a..1493a87142e59 100644 --- a/packages/@aws-cdk/aws-iot-actions/lib/iot-republish-action.ts +++ b/packages/@aws-cdk/aws-iot-actions/lib/iot-republish-action.ts @@ -4,11 +4,11 @@ import { CommonActionProps } from './common-action-props'; import { singletonActionRole } from './private/role'; /** - * MQTT Quality of Service + * MQTT Quality of Service (QoS) indicates the level of assurance for delivery of an MQTT Message. * * @see https://docs.aws.amazon.com/iot/latest/developerguide/mqtt.html#mqtt-qos */ -export enum MqttQos { +export enum MqttQualityOfService { /** * QoS level 0. Sent zero or more times. * This level should be used for messages that are sent over reliable communication links or that can be missed without a problem. @@ -25,29 +25,29 @@ export enum MqttQos { /** * Configuration properties of an action to republish MQTT messages. */ -export interface IotRepublishActionProps extends CommonActionProps { +export interface IotRepublishMqttActionProps extends CommonActionProps { /** * The Quality of Service (QoS) level to use when republishing messages. * * @see https://docs.aws.amazon.com/iot/latest/developerguide/mqtt.html#mqtt-qos * - * @default MqttQos.ZERO_OR_MORE_TIMES + * @default MqttQualityOfService.ZERO_OR_MORE_TIMES */ - readonly qos?: MqttQos; + readonly qos?: MqttQualityOfService; } /** * The action to put the record from an MQTT message to republish another MQTT topic. */ -export class IotRepublishAction implements iot.IAction { - private readonly qos?: MqttQos; +export class IotRepublishMqttAction implements iot.IAction { + private readonly qos?: MqttQualityOfService; private readonly role?: iam.IRole; /** * @param topic The MQTT topic to which to republish the message. - * @param props Optional properties to not use default + * @param props Optional properties to not use default. */ - constructor(private readonly topic: string, props: IotRepublishActionProps = {}) { + constructor(private readonly topic: string, props: IotRepublishMqttActionProps = {}) { this.qos = props.qos; this.role = props.role; } diff --git a/packages/@aws-cdk/aws-iot-actions/test/iot/integ.iot-republish-action.ts b/packages/@aws-cdk/aws-iot-actions/test/iot/integ.iot-republish-action.ts index 762be15e487d1..d2fbf311b0c5c 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/iot/integ.iot-republish-action.ts +++ b/packages/@aws-cdk/aws-iot-actions/test/iot/integ.iot-republish-action.ts @@ -13,8 +13,8 @@ class TestStack extends cdk.Stack { }); topicRule.addAction( - new actions.IotRepublishAction('${topic()}/republish', { - qos: actions.MqttQos.AT_LEAST_ONCE, + new actions.IotRepublishMqttAction('${topic()}/republish', { + qos: actions.MqttQualityOfService.AT_LEAST_ONCE, }), ); } diff --git a/packages/@aws-cdk/aws-iot-actions/test/iot/iot-republish-action.test.ts b/packages/@aws-cdk/aws-iot-actions/test/iot/iot-republish-action.test.ts index c38404a490e54..29e66ae339516 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/iot/iot-republish-action.test.ts +++ b/packages/@aws-cdk/aws-iot-actions/test/iot/iot-republish-action.test.ts @@ -4,20 +4,19 @@ import * as iot from '@aws-cdk/aws-iot'; import * as cdk from '@aws-cdk/core'; import * as actions from '../../lib'; -let stack:cdk.Stack; +let stack: cdk.Stack; +let topicRule:iot.TopicRule; beforeEach(() => { stack = new cdk.Stack(); -}); - -test('Default IoT republish action', () => { - // GIVEN - const topicRule = new iot.TopicRule(stack, 'MyTopicRule', { + topicRule = new iot.TopicRule(stack, 'MyTopicRule', { sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id FROM 'device/+/data'"), }); +}); +test('Default IoT republish action', () => { // WHEN topicRule.addAction( - new actions.IotRepublishAction('test-topic'), + new actions.IotRepublishMqttAction('test-topic'), ); // THEN @@ -70,14 +69,9 @@ test('Default IoT republish action', () => { }); test('can set qos', () => { - // GIVEN - const topicRule = new iot.TopicRule(stack, 'MyTopicRule', { - sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id FROM 'device/+/data'"), - }); - // WHEN topicRule.addAction( - new actions.IotRepublishAction('test-topic', { qos: actions.MqttQos.AT_LEAST_ONCE }), + new actions.IotRepublishMqttAction('test-topic', { qos: actions.MqttQualityOfService.AT_LEAST_ONCE }), ); // THEN @@ -91,15 +85,10 @@ test('can set qos', () => { }); test('can set role', () => { - // GIVEN - const topicRule = new iot.TopicRule(stack, 'MyTopicRule', { - sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id FROM 'device/+/data'"), - }); - const role = iam.Role.fromRoleArn(stack, 'MyRole', 'arn:aws:iam::123456789012:role/ForTest'); - // WHEN + const role = iam.Role.fromRoleArn(stack, 'MyRole', 'arn:aws:iam::123456789012:role/ForTest'); topicRule.addAction( - new actions.IotRepublishAction('test-topic', { role }), + new actions.IotRepublishMqttAction('test-topic', { role }), ); // THEN From 4868f69fea844303cdc3819cea3ad9d981819d2a Mon Sep 17 00:00:00 2001 From: yamatatsu Date: Fri, 28 Jan 2022 20:33:55 +0900 Subject: [PATCH 4/4] rename qos --- packages/@aws-cdk/aws-iot-actions/README.md | 2 +- .../@aws-cdk/aws-iot-actions/lib/iot-republish-action.ts | 8 ++++---- .../test/iot/integ.iot-republish-action.ts | 2 +- .../aws-iot-actions/test/iot/iot-republish-action.test.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/@aws-cdk/aws-iot-actions/README.md b/packages/@aws-cdk/aws-iot-actions/README.md index 9350408859996..860643683efd1 100644 --- a/packages/@aws-cdk/aws-iot-actions/README.md +++ b/packages/@aws-cdk/aws-iot-actions/README.md @@ -41,7 +41,7 @@ new iot.TopicRule(this, 'TopicRule', { sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id, timestamp() as timestamp, temperature FROM 'device/+/data'"), actions: [ new actions.IotRepublishMqttAction('${topic()}/republish', { - qos: actions.MqttQualityOfService.AT_LEAST_ONCE, // optional property, default is MqttQualityOfService.ZERO_OR_MORE_TIMES + qualityOfService: actions.MqttQualityOfService.AT_LEAST_ONCE, // optional property, default is MqttQualityOfService.ZERO_OR_MORE_TIMES }), ], }); diff --git a/packages/@aws-cdk/aws-iot-actions/lib/iot-republish-action.ts b/packages/@aws-cdk/aws-iot-actions/lib/iot-republish-action.ts index 1493a87142e59..77aadb876c4d9 100644 --- a/packages/@aws-cdk/aws-iot-actions/lib/iot-republish-action.ts +++ b/packages/@aws-cdk/aws-iot-actions/lib/iot-republish-action.ts @@ -33,14 +33,14 @@ export interface IotRepublishMqttActionProps extends CommonActionProps { * * @default MqttQualityOfService.ZERO_OR_MORE_TIMES */ - readonly qos?: MqttQualityOfService; + readonly qualityOfService?: MqttQualityOfService; } /** * The action to put the record from an MQTT message to republish another MQTT topic. */ export class IotRepublishMqttAction implements iot.IAction { - private readonly qos?: MqttQualityOfService; + private readonly qualityOfService?: MqttQualityOfService; private readonly role?: iam.IRole; /** @@ -48,7 +48,7 @@ export class IotRepublishMqttAction implements iot.IAction { * @param props Optional properties to not use default. */ constructor(private readonly topic: string, props: IotRepublishMqttActionProps = {}) { - this.qos = props.qos; + this.qualityOfService = props.qualityOfService; this.role = props.role; } @@ -63,7 +63,7 @@ export class IotRepublishMqttAction implements iot.IAction { configuration: { republish: { topic: this.topic, - qos: this.qos, + qos: this.qualityOfService, roleArn: role.roleArn, }, }, diff --git a/packages/@aws-cdk/aws-iot-actions/test/iot/integ.iot-republish-action.ts b/packages/@aws-cdk/aws-iot-actions/test/iot/integ.iot-republish-action.ts index d2fbf311b0c5c..d5a71b32f6a0d 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/iot/integ.iot-republish-action.ts +++ b/packages/@aws-cdk/aws-iot-actions/test/iot/integ.iot-republish-action.ts @@ -14,7 +14,7 @@ class TestStack extends cdk.Stack { topicRule.addAction( new actions.IotRepublishMqttAction('${topic()}/republish', { - qos: actions.MqttQualityOfService.AT_LEAST_ONCE, + qualityOfService: actions.MqttQualityOfService.AT_LEAST_ONCE, }), ); } diff --git a/packages/@aws-cdk/aws-iot-actions/test/iot/iot-republish-action.test.ts b/packages/@aws-cdk/aws-iot-actions/test/iot/iot-republish-action.test.ts index 29e66ae339516..8a78e272285ef 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/iot/iot-republish-action.test.ts +++ b/packages/@aws-cdk/aws-iot-actions/test/iot/iot-republish-action.test.ts @@ -68,10 +68,10 @@ test('Default IoT republish action', () => { }); }); -test('can set qos', () => { +test('can set qualityOfService', () => { // WHEN topicRule.addAction( - new actions.IotRepublishMqttAction('test-topic', { qos: actions.MqttQualityOfService.AT_LEAST_ONCE }), + new actions.IotRepublishMqttAction('test-topic', { qualityOfService: actions.MqttQualityOfService.AT_LEAST_ONCE }), ); // THEN