From 95d0806b14fb7396da0ac8b62046367929267c58 Mon Sep 17 00:00:00 2001 From: Constantin Ponfick Date: Thu, 11 May 2023 14:54:36 +0200 Subject: [PATCH 1/5] added iot https action --- .../aws-iot-actions-alpha/lib/https-action.ts | 96 +++++++++ .../aws-iot-actions-alpha/lib/index.ts | 1 + .../test/https/https-action.test.ts | 161 ++++++++++++++ ...efaultTestDeployAssert019947CA.assets.json | 19 ++ ...aultTestDeployAssert019947CA.template.json | 36 ++++ .../IoTHttpsActionTestStack.assets.json | 19 ++ .../IoTHttpsActionTestStack.template.json | 94 ++++++++ .../integ.https-action.js.snapshot/cdk.out | 1 + .../integ.https-action.js.snapshot/integ.json | 12 ++ .../manifest.json | 117 ++++++++++ .../integ.https-action.js.snapshot/tree.json | 201 ++++++++++++++++++ .../test/https/integ.https-action.ts | 36 ++++ 12 files changed, 793 insertions(+) create mode 100644 packages/@aws-cdk/aws-iot-actions-alpha/lib/https-action.ts create mode 100644 packages/@aws-cdk/aws-iot-actions-alpha/test/https/https-action.test.ts create mode 100644 packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/IoTHttpsActionDefaultTestDeployAssert019947CA.assets.json create mode 100644 packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/IoTHttpsActionDefaultTestDeployAssert019947CA.template.json create mode 100644 packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/IoTHttpsActionTestStack.assets.json create mode 100644 packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/IoTHttpsActionTestStack.template.json create mode 100644 packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/integ.json create mode 100644 packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/tree.json create mode 100644 packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.ts diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/lib/https-action.ts b/packages/@aws-cdk/aws-iot-actions-alpha/lib/https-action.ts new file mode 100644 index 0000000000000..a08c3bf9d2bac --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions-alpha/lib/https-action.ts @@ -0,0 +1,96 @@ +import * as iot from '@aws-cdk/aws-iot-alpha'; +import * as iam from 'aws-cdk-lib/aws-iam'; +import { CommonActionProps } from './common-action-props'; +import { singletonActionRole } from './private/role'; + +export interface HttpActionSigV4Auth { + /** + * The service name. + */ + readonly serviceName: string; + /** + * The signing region. + */ + readonly signingRegion: string; +} + +export interface HttpActionHeader { + /** + * The HTTP header key. + */ + readonly key: string; + /** + * The HTTP header value. Substitution templates are supported. + */ + readonly value: string; +} + +/** + * Configuration properties of an HTTPS action. + * + * @see https://docs.aws.amazon.com/iot/latest/developerguide/https-rule-action.html + */ +export interface HttpsActionProps extends CommonActionProps { + /** + * If specified, AWS IoT uses the confirmation URL to create a matching topic rule destination. + */ + readonly confirmationUrl?: string; + + /** + * The headers to include in the HTTPS request to the endpoint. + */ + readonly headers?: Array; + + /** + * Use Sigv4 authorization. + */ + readonly auth?: HttpActionSigV4Auth; +} + +/** + * The action to send data from an MQTT message to a web application or service. + */ +export class HttpsAction implements iot.IAction { + private readonly role?: iam.IRole; + private readonly url: string; + private readonly confirmationUrl?: string; + private readonly headers?: Array; + private readonly auth?: HttpActionSigV4Auth; + + /** + * @param url The url to which to send post request. + * @param props Optional properties to not use default. + */ + constructor( url: string, props: HttpsActionProps={}) { + this.url = url; + this.confirmationUrl = props.confirmationUrl; + this.headers = props.headers; + this.role = props.role; + this.auth = props.auth; + } + + /** + * @internal + */ + public _bind(topicRule: iot.ITopicRule): iot.ActionConfig { + const role = this.role ?? singletonActionRole(topicRule); + const sigV4 = this.auth ? { + sigv4: { + roleArn: role.roleArn, + serviceName: this.auth.serviceName, + signingRegion: this.auth.signingRegion, + }, + } : this.auth; + + return { + configuration: { + http: { + url: this.url, + confirmationUrl: this.confirmationUrl, + headers: this.headers, + auth: sigV4, + }, + }, + }; + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/lib/index.ts b/packages/@aws-cdk/aws-iot-actions-alpha/lib/index.ts index 0a9d23398f59b..42bf6a4cb96ea 100644 --- a/packages/@aws-cdk/aws-iot-actions-alpha/lib/index.ts +++ b/packages/@aws-cdk/aws-iot-actions-alpha/lib/index.ts @@ -11,3 +11,4 @@ export * from './lambda-function-action'; export * from './s3-put-object-action'; export * from './sqs-queue-action'; export * from './sns-topic-action'; +export * from './https-action'; diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/test/https/https-action.test.ts b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/https-action.test.ts new file mode 100644 index 0000000000000..eafd986ce54b1 --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/https-action.test.ts @@ -0,0 +1,161 @@ +import { Template, Match } from 'aws-cdk-lib/assertions'; +import * as iot from '@aws-cdk/aws-iot-alpha'; +import * as cdk from 'aws-cdk-lib'; +import * as actions from '../../lib'; + +test('Default HTTPS action', () => { + // GIVEN + const stack = new cdk.Stack(); + const topicRule = new iot.TopicRule(stack, 'MyTopicRule', { + sql: iot.IotSql.fromStringAsVer20160323( + "SELECT topic(2) as device_id FROM 'device/+/data'", + ), + }); + const expectedUrl = 'https://example.com'; + + // WHEN + topicRule.addAction(new actions.HttpsAction(expectedUrl)); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::IoT::TopicRule', { + TopicRulePayload: { + Actions: [ + { + Http: { + Url: expectedUrl, + }, + }, + ], + }, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { + AssumeRolePolicyDocument: { + Statement: [ + { + Action: 'sts:AssumeRole', + Effect: 'Allow', + Principal: { + Service: 'iot.amazonaws.com', + }, + }, + ], + Version: '2012-10-17', + }, + }); +}); + +test('can set confirmation url', () => { + // GIVEN + const stack = new cdk.Stack(); + const topicRule = new iot.TopicRule(stack, 'MyTopicRule', { + sql: iot.IotSql.fromStringAsVer20160323( + "SELECT topic(2) as device_id FROM 'device/+/data'", + ), + }); + const expectedUrl = 'https://example.com'; + const expectedConfirmationUrl = 'https://example.com/confirm'; + + // WHEN + topicRule.addAction( + new actions.HttpsAction(expectedUrl, { + confirmationUrl: expectedConfirmationUrl, + }), + ); + + //THEN + Template.fromStack(stack).hasResourceProperties('AWS::IoT::TopicRule', { + TopicRulePayload: { + Actions: [ + { + Http: { + Url: expectedUrl, + ConfirmationUrl: expectedConfirmationUrl, + }, + }, + ], + }, + }); +}); + +test('can set http headers', () => { + // GIVEN + const stack = new cdk.Stack(); + const topicRule = new iot.TopicRule(stack, 'MyTopicRule', { + sql: iot.IotSql.fromStringAsVer20160323( + "SELECT topic(2) as device_id FROM 'device/+/data'", + ), + }); + const expectedUrl = 'https://example.com'; + const headers = [ + { key: 'key0', value: 'value0' }, + { key: 'key1', value: 'value1' }, + ]; + + // WHEN + topicRule.addAction( + new actions.HttpsAction(expectedUrl, { headers: headers }), + ); + + //THEN + Template.fromStack(stack).hasResourceProperties('AWS::IoT::TopicRule', { + TopicRulePayload: { + Actions: [ + { + Http: { + Url: expectedUrl, + Headers: [ + { Key: 'key0', Value: 'value0' }, + { Key: 'key1', Value: 'value1' }, + ], + }, + }, + ], + }, + }); +}); + +test('can set http auth', () => { + // GIVEN + const stack = new cdk.Stack(); + const topicRule = new iot.TopicRule(stack, 'MyTopicRule', { + sql: iot.IotSql.fromStringAsVer20160323( + "SELECT topic(2) as device_id FROM 'device/+/data'", + ), + }); + const expectedUrl = 'https://example.com'; + const expectedAuth = { + serviceName: 'serviceName', + signingRegion: 'signingName', + }; + + // WHEN + topicRule.addAction( + new actions.HttpsAction(expectedUrl, { auth: expectedAuth }), + ); + + //THEN + Template.fromStack(stack).hasResourceProperties('AWS::IoT::TopicRule', { + TopicRulePayload: { + Actions: [ + { + Http: { + Url: expectedUrl, + Auth: { + Sigv4: { + RoleArn: { + 'Fn::GetAtt': [ + Match.stringLikeRegexp('MyTopicRuleTopicRuleActionRole'), + 'Arn', + ], + }, + ServiceName: expectedAuth.serviceName, + SigningRegion: expectedAuth.signingRegion, + }, + }, + }, + }, + ], + }, + }); +}); diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/IoTHttpsActionDefaultTestDeployAssert019947CA.assets.json b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/IoTHttpsActionDefaultTestDeployAssert019947CA.assets.json new file mode 100644 index 0000000000000..04e4714435a66 --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/IoTHttpsActionDefaultTestDeployAssert019947CA.assets.json @@ -0,0 +1,19 @@ +{ + "version": "31.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "IoTHttpsActionDefaultTestDeployAssert019947CA.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/IoTHttpsActionDefaultTestDeployAssert019947CA.template.json b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/IoTHttpsActionDefaultTestDeployAssert019947CA.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/IoTHttpsActionDefaultTestDeployAssert019947CA.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/IoTHttpsActionTestStack.assets.json b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/IoTHttpsActionTestStack.assets.json new file mode 100644 index 0000000000000..80820fc0ff5e0 --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/IoTHttpsActionTestStack.assets.json @@ -0,0 +1,19 @@ +{ + "version": "31.0.0", + "files": { + "ceb4c33f2a2723481892f941c88433106a7019ed281d49385fdbaf9f0b09a343": { + "source": { + "path": "IoTHttpsActionTestStack.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "ceb4c33f2a2723481892f941c88433106a7019ed281d49385fdbaf9f0b09a343.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/IoTHttpsActionTestStack.template.json b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/IoTHttpsActionTestStack.template.json new file mode 100644 index 0000000000000..d55dcc392a303 --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/IoTHttpsActionTestStack.template.json @@ -0,0 +1,94 @@ +{ + "Resources": { + "TopicRule40A4EA44": { + "Type": "AWS::IoT::TopicRule", + "Properties": { + "TopicRulePayload": { + "Actions": [ + { + "Http": { + "Auth": { + "Sigv4": { + "RoleArn": { + "Fn::GetAtt": [ + "TopicRuleTopicRuleActionRole246C4F77", + "Arn" + ] + }, + "ServiceName": "serviceName", + "SigningRegion": "us-east-1" + } + }, + "ConfirmationUrl": "https://example.com", + "Headers": [ + { + "Key": "key0", + "Value": "value0" + }, + { + "Key": "key1", + "Value": "value1" + } + ], + "Url": "https://example.com/endpoint" + } + } + ], + "AwsIotSqlVersion": "2016-03-23", + "Sql": "SELECT topic(2) as device_id, year, month, day 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" + } + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/cdk.out b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/cdk.out new file mode 100644 index 0000000000000..7925065efbcc4 --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"31.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/integ.json b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/integ.json new file mode 100644 index 0000000000000..9ebcd3a75036a --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "31.0.0", + "testCases": { + "IoTHttpsAction/DefaultTest": { + "stacks": [ + "IoTHttpsActionTestStack" + ], + "assertionStack": "IoTHttpsAction/DefaultTest/DeployAssert", + "assertionStackName": "IoTHttpsActionDefaultTestDeployAssert019947CA" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/manifest.json b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/manifest.json new file mode 100644 index 0000000000000..4caf31016c1a7 --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/manifest.json @@ -0,0 +1,117 @@ +{ + "version": "31.0.0", + "artifacts": { + "IoTHttpsActionTestStack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "IoTHttpsActionTestStack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "IoTHttpsActionTestStack": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "IoTHttpsActionTestStack.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/ceb4c33f2a2723481892f941c88433106a7019ed281d49385fdbaf9f0b09a343.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "IoTHttpsActionTestStack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "IoTHttpsActionTestStack.assets" + ], + "metadata": { + "/IoTHttpsActionTestStack/TopicRule/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "TopicRule40A4EA44" + } + ], + "/IoTHttpsActionTestStack/TopicRule/TopicRuleActionRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "TopicRuleTopicRuleActionRole246C4F77" + } + ], + "/IoTHttpsActionTestStack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/IoTHttpsActionTestStack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "IoTHttpsActionTestStack" + }, + "IoTHttpsActionDefaultTestDeployAssert019947CA.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "IoTHttpsActionDefaultTestDeployAssert019947CA.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "IoTHttpsActionDefaultTestDeployAssert019947CA": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "IoTHttpsActionDefaultTestDeployAssert019947CA.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "IoTHttpsActionDefaultTestDeployAssert019947CA.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "IoTHttpsActionDefaultTestDeployAssert019947CA.assets" + ], + "metadata": { + "/IoTHttpsAction/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/IoTHttpsAction/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "IoTHttpsAction/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/tree.json b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/tree.json new file mode 100644 index 0000000000000..ba46340ffa5b0 --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.js.snapshot/tree.json @@ -0,0 +1,201 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "IoTHttpsActionTestStack": { + "id": "IoTHttpsActionTestStack", + "path": "IoTHttpsActionTestStack", + "children": { + "TopicRule": { + "id": "TopicRule", + "path": "IoTHttpsActionTestStack/TopicRule", + "children": { + "Resource": { + "id": "Resource", + "path": "IoTHttpsActionTestStack/TopicRule/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IoT::TopicRule", + "aws:cdk:cloudformation:props": { + "topicRulePayload": { + "actions": [ + { + "http": { + "url": "https://example.com/endpoint", + "confirmationUrl": "https://example.com", + "headers": [ + { + "key": "key0", + "value": "value0" + }, + { + "key": "key1", + "value": "value1" + } + ], + "auth": { + "sigv4": { + "roleArn": { + "Fn::GetAtt": [ + "TopicRuleTopicRuleActionRole246C4F77", + "Arn" + ] + }, + "serviceName": "serviceName", + "signingRegion": "us-east-1" + } + } + } + } + ], + "awsIotSqlVersion": "2016-03-23", + "sql": "SELECT topic(2) as device_id, year, month, day FROM 'device/+/data'" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iot.CfnTopicRule", + "version": "0.0.0" + } + }, + "TopicRuleActionRole": { + "id": "TopicRuleActionRole", + "path": "IoTHttpsActionTestStack/TopicRule/TopicRuleActionRole", + "children": { + "ImportTopicRuleActionRole": { + "id": "ImportTopicRuleActionRole", + "path": "IoTHttpsActionTestStack/TopicRule/TopicRuleActionRole/ImportTopicRuleActionRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "IoTHttpsActionTestStack/TopicRule/TopicRuleActionRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "iot.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iot-alpha.TopicRule", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "IoTHttpsActionTestStack/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "IoTHttpsActionTestStack/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "IoTHttpsAction": { + "id": "IoTHttpsAction", + "path": "IoTHttpsAction", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "IoTHttpsAction/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "IoTHttpsAction/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.18" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "IoTHttpsAction/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "IoTHttpsAction/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "IoTHttpsAction/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.18" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.ts b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.ts new file mode 100644 index 0000000000000..0d89fa1ab0521 --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions-alpha/test/https/integ.https-action.ts @@ -0,0 +1,36 @@ +import * as iot from '@aws-cdk/aws-iot-alpha'; +import * as cdk from 'aws-cdk-lib'; +import * as actions from '../../lib'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; + +const app = new cdk.App(); + +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 topic(2) as device_id, year, month, day FROM 'device/+/data'", + ), + }); + + topicRule.addAction( + new actions.HttpsAction('https://example.com/endpoint', { + confirmationUrl: 'https://example.com', + headers: [ + { key: 'key0', value: 'value0' }, + { key: 'key1', value: 'value1' }, + ], + auth: { serviceName: 'serviceName', signingRegion: 'us-east-1' }, + }), + ); + } +} + +const stack = new TestStack(app, 'IoTHttpsActionTestStack'); +new IntegTest(app, 'IoTHttpsAction', { + testCases: [stack], +}); + +app.synth(); From 6843d201e75c1201bb86588f7dae4f4d7372c557 Mon Sep 17 00:00:00 2001 From: Constantin Ponfick Date: Thu, 11 May 2023 15:06:31 +0200 Subject: [PATCH 2/5] added section to readme --- .../@aws-cdk/aws-iot-actions-alpha/README.md | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/README.md b/packages/@aws-cdk/aws-iot-actions-alpha/README.md index 10d076a1ad780..3e7a0626cbc4e 100644 --- a/packages/@aws-cdk/aws-iot-actions-alpha/README.md +++ b/packages/@aws-cdk/aws-iot-actions-alpha/README.md @@ -33,6 +33,7 @@ Currently supported are: - Publish messages on SNS topics - Write messages into columns of DynamoDB - Put messages IoT Events input +- Send messages to HTTPS endpoints ## Republish a message to another MQTT topic @@ -328,3 +329,31 @@ const topicRule = new iot.TopicRule(this, 'TopicRule', { ], }); ``` + +## Send messages to HTTPS endpoints + +The code snippet below creates an AWS IoT Rule that sends messages +to an HTTPS endpoint when it is triggered: + +```ts +import * as iot from '@aws-cdk/aws-iot-alpha'; +import * as actions from '../../lib'; + +const topicRule = new iot.TopicRule(this, 'TopicRule', { + sql: iot.IotSql.fromStringAsVer20160323( + "SELECT topic(2) as device_id, year, month, day FROM 'device/+/data'", + ), + }); + + topicRule.addAction( + new actions.HttpsAction('https://example.com/endpoint', { + confirmationUrl: 'https://example.com', + headers: [ + { key: 'key0', value: 'value0' }, + { key: 'key1', value: 'value1' }, + ], + auth: { serviceName: 'serviceName', signingRegion: 'us-east-1' }, + }), + ); +} +``` \ No newline at end of file From cfc65f188463bc93db1293243423ac932999ec88 Mon Sep 17 00:00:00 2001 From: Constantin Ponfick Date: Thu, 11 May 2023 15:31:18 +0200 Subject: [PATCH 3/5] fixed linting in readme --- packages/@aws-cdk/aws-iot-actions-alpha/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/README.md b/packages/@aws-cdk/aws-iot-actions-alpha/README.md index 3e7a0626cbc4e..5d688ec03ca74 100644 --- a/packages/@aws-cdk/aws-iot-actions-alpha/README.md +++ b/packages/@aws-cdk/aws-iot-actions-alpha/README.md @@ -356,4 +356,4 @@ const topicRule = new iot.TopicRule(this, 'TopicRule', { }), ); } -``` \ No newline at end of file +``` From 2df4b7b9eb7e4b10eade0b0a7d381bbf587c4d95 Mon Sep 17 00:00:00 2001 From: Constantin Ponfick Date: Thu, 11 May 2023 16:08:51 +0200 Subject: [PATCH 4/5] adjusted title --- packages/@aws-cdk/aws-iot-actions-alpha/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/README.md b/packages/@aws-cdk/aws-iot-actions-alpha/README.md index 5d688ec03ca74..509e0f2a924a9 100644 --- a/packages/@aws-cdk/aws-iot-actions-alpha/README.md +++ b/packages/@aws-cdk/aws-iot-actions-alpha/README.md @@ -330,7 +330,7 @@ const topicRule = new iot.TopicRule(this, 'TopicRule', { }); ``` -## Send messages to HTTPS endpoints +## Send Messages to HTTPS Endpoints The code snippet below creates an AWS IoT Rule that sends messages to an HTTPS endpoint when it is triggered: From 946315d07fcdf7d82777fc4a7930e2c56ce1dbc5 Mon Sep 17 00:00:00 2001 From: Constantin Ponfick Date: Thu, 11 May 2023 16:44:44 +0200 Subject: [PATCH 5/5] removed imports from readme --- packages/@aws-cdk/aws-iot-actions-alpha/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/README.md b/packages/@aws-cdk/aws-iot-actions-alpha/README.md index 509e0f2a924a9..27786455a1f8d 100644 --- a/packages/@aws-cdk/aws-iot-actions-alpha/README.md +++ b/packages/@aws-cdk/aws-iot-actions-alpha/README.md @@ -336,9 +336,6 @@ The code snippet below creates an AWS IoT Rule that sends messages to an HTTPS endpoint when it is triggered: ```ts -import * as iot from '@aws-cdk/aws-iot-alpha'; -import * as actions from '../../lib'; - const topicRule = new iot.TopicRule(this, 'TopicRule', { sql: iot.IotSql.fromStringAsVer20160323( "SELECT topic(2) as device_id, year, month, day FROM 'device/+/data'",