From 232fa3900e12f9716453a65dab4c5ff2d13bd49c Mon Sep 17 00:00:00 2001 From: BobVeringa Date: Mon, 2 May 2022 14:37:29 +0000 Subject: [PATCH 01/14] Add support for DynamoDBv2 iot rule action --- .../lib/dynamo-db-v2-put-item.ts | 45 ++++ .../@aws-cdk/aws-iot-actions/lib/index.ts | 1 + .../@aws-cdk/aws-iot-actions/package.json | 2 + .../cdk.out | 1 + .../integ.json | 14 ++ .../manifest.json | 54 +++++ ...-kinesis-stream-action-stack.template.json | 105 +++++++++ .../tree.json | 210 ++++++++++++++++++ .../dynamodb-v2-put-item-action.test.ts | 96 ++++++++ ...teg.dynamodb-put-item-action.expected.json | 105 +++++++++ .../integ.dynamodb-v2-put-item-action.ts | 40 ++++ packages/aws-cdk-lib/package.json | 2 + 12 files changed, 675 insertions(+) create mode 100644 packages/@aws-cdk/aws-iot-actions/lib/dynamo-db-v2-put-item.ts create mode 100644 packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/cdk.out create mode 100644 packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/integ.json create mode 100644 packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/manifest.json create mode 100644 packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/test-kinesis-stream-action-stack.template.json create mode 100644 packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/tree.json create mode 100644 packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.test.ts create mode 100644 packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-put-item-action.expected.json create mode 100644 packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts diff --git a/packages/@aws-cdk/aws-iot-actions/lib/dynamo-db-v2-put-item.ts b/packages/@aws-cdk/aws-iot-actions/lib/dynamo-db-v2-put-item.ts new file mode 100644 index 0000000000000..eeabe17c0579e --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions/lib/dynamo-db-v2-put-item.ts @@ -0,0 +1,45 @@ +import * as dynamodb from '@aws-cdk/aws-dynamodb'; +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'; + +/** + * Configuration properties of an action for the dynamodb table. + */ +export interface DynamoDBv2PutItemActionProps extends CommonActionProps { +} + + +/** + * The action to put the record from an MQTT message to the Kinesis Data Firehose stream. + */ +export class DynamoDBv2PutItemAction implements iot.IAction { + private readonly role?: iam.IRole; + + /** + * @param table the DynamoDB table in which to put the items. + * @param props Optional properties to not use default + */ + constructor(private readonly table: dynamodb.ITable, props: DynamoDBv2PutItemActionProps = {}) { + this.role = props.role; + } + + bind(rule: iot.ITopicRule): iot.ActionConfig { + const role = this.role ?? singletonActionRole(rule); + role.addToPrincipalPolicy(new iam.PolicyStatement({ + actions: ['dynamodb:PutItem'], + resources: [this.table.tableArn], + })); + return { + configuration: { + dynamoDBv2: { + putItem: { + tableName: this.table.tableName, + }, + roleArn: role.roleArn, + }, + }, + }; + } +} diff --git a/packages/@aws-cdk/aws-iot-actions/lib/index.ts b/packages/@aws-cdk/aws-iot-actions/lib/index.ts index 5c214f4143309..7e62efee286a1 100644 --- a/packages/@aws-cdk/aws-iot-actions/lib/index.ts +++ b/packages/@aws-cdk/aws-iot-actions/lib/index.ts @@ -2,6 +2,7 @@ export * from './cloudwatch-logs-action'; export * from './cloudwatch-put-metric-action'; export * from './cloudwatch-set-alarm-state-action'; export * from './common-action-props'; +export * from './dynamo-db-v2-put-item'; export * from './firehose-put-record-action'; export * from './iot-republish-action'; export * from './kinesis-put-record-action'; diff --git a/packages/@aws-cdk/aws-iot-actions/package.json b/packages/@aws-cdk/aws-iot-actions/package.json index 5b0cbe2f08344..3b40ceeb1aa1e 100644 --- a/packages/@aws-cdk/aws-iot-actions/package.json +++ b/packages/@aws-cdk/aws-iot-actions/package.json @@ -88,6 +88,7 @@ }, "dependencies": { "@aws-cdk/aws-cloudwatch": "0.0.0", + "@aws-cdk/aws-dynamodb": "0.0.0", "@aws-cdk/aws-iam": "0.0.0", "@aws-cdk/aws-iot": "0.0.0", "@aws-cdk/aws-kinesis": "0.0.0", @@ -104,6 +105,7 @@ "homepage": "https://github.com/aws/aws-cdk", "peerDependencies": { "@aws-cdk/aws-cloudwatch": "0.0.0", + "@aws-cdk/aws-dynamodb": "0.0.0", "@aws-cdk/aws-iam": "0.0.0", "@aws-cdk/aws-iot": "0.0.0", "@aws-cdk/aws-kinesis": "0.0.0", diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/cdk.out b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/cdk.out new file mode 100644 index 0000000000000..2efc89439fab8 --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"18.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/integ.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/integ.json new file mode 100644 index 0000000000000..d2e5d9c2da04e --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/integ.json @@ -0,0 +1,14 @@ +{ + "version": "18.0.0", + "testCases": { + "dynamodb-v2/integ.dynamodb-v2-put-item-action": { + "stacks": [ + "test-kinesis-stream-action-stack" + ], + "diffAssets": false, + "stackUpdateWorkflow": true + } + }, + "synthContext": {}, + "enableLookups": false +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/manifest.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/manifest.json new file mode 100644 index 0000000000000..a78a3968b54de --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/manifest.json @@ -0,0 +1,54 @@ +{ + "version": "18.0.0", + "artifacts": { + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + }, + "test-kinesis-stream-action-stack": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "test-kinesis-stream-action-stack.template.json", + "validateOnSynth": false + }, + "metadata": { + "/test-kinesis-stream-action-stack/TopicRule/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "TopicRule40A4EA44" + } + ], + "/test-kinesis-stream-action-stack/TopicRule/TopicRuleActionRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "TopicRuleTopicRuleActionRole246C4F77" + } + ], + "/test-kinesis-stream-action-stack/TopicRule/TopicRuleActionRole/DefaultPolicy/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "TopicRuleTopicRuleActionRoleDefaultPolicy99ADD687" + } + ], + "/test-kinesis-stream-action-stack/MyTable": [ + { + "type": "aws:cdk:hasPhysicalName", + "data": { + "Ref": "MyTable794EDED1" + } + } + ], + "/test-kinesis-stream-action-stack/MyTable/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyTable794EDED1" + } + ] + }, + "displayName": "test-kinesis-stream-action-stack" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/test-kinesis-stream-action-stack.template.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/test-kinesis-stream-action-stack.template.json new file mode 100644 index 0000000000000..ca48050d2ceb4 --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/test-kinesis-stream-action-stack.template.json @@ -0,0 +1,105 @@ +{ + "Resources": { + "TopicRule40A4EA44": { + "Type": "AWS::IoT::TopicRule", + "Properties": { + "TopicRulePayload": { + "Actions": [ + { + "DynamoDBv2": { + "PutItem": { + "TableName": { + "Ref": "MyTable794EDED1" + } + }, + "RoleArn": { + "Fn::GetAtt": [ + "TopicRuleTopicRuleActionRole246C4F77", + "Arn" + ] + } + } + } + ], + "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": "dynamodb:PutItem", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyTable794EDED1", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "TopicRuleTopicRuleActionRoleDefaultPolicy99ADD687", + "Roles": [ + { + "Ref": "TopicRuleTopicRuleActionRole246C4F77" + } + ] + } + }, + "MyTable794EDED1": { + "Type": "AWS::DynamoDB::Table", + "Properties": { + "KeySchema": [ + { + "AttributeName": "hashKey", + "KeyType": "HASH" + }, + { + "AttributeName": "sortKey", + "KeyType": "RANGE" + } + ], + "AttributeDefinitions": [ + { + "AttributeName": "hashKey", + "AttributeType": "S" + }, + { + "AttributeName": "sortKey", + "AttributeType": "N" + } + ], + "ProvisionedThroughput": { + "ReadCapacityUnits": 1, + "WriteCapacityUnits": 1 + }, + "TableName": "MyTable" + }, + "UpdateReplacePolicy": "Retain", + "DeletionPolicy": "Retain" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/tree.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/tree.json new file mode 100644 index 0000000000000..9ef9a3e79ee29 --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/tree.json @@ -0,0 +1,210 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "@aws-cdk/core.Construct", + "version": "0.0.0" + } + }, + "test-kinesis-stream-action-stack": { + "id": "test-kinesis-stream-action-stack", + "path": "test-kinesis-stream-action-stack", + "children": { + "TopicRule": { + "id": "TopicRule", + "path": "test-kinesis-stream-action-stack/TopicRule", + "children": { + "Resource": { + "id": "Resource", + "path": "test-kinesis-stream-action-stack/TopicRule/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IoT::TopicRule", + "aws:cdk:cloudformation:props": { + "topicRulePayload": { + "actions": [ + { + "dynamoDBv2": { + "putItem": { + "tableName": { + "Ref": "MyTable794EDED1" + } + }, + "roleArn": { + "Fn::GetAtt": [ + "TopicRuleTopicRuleActionRole246C4F77", + "Arn" + ] + } + } + } + ], + "awsIotSqlVersion": "2016-03-23", + "sql": "SELECT * FROM 'device/+/data'" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iot.CfnTopicRule", + "version": "0.0.0" + } + }, + "TopicRuleActionRole": { + "id": "TopicRuleActionRole", + "path": "test-kinesis-stream-action-stack/TopicRule/TopicRuleActionRole", + "children": { + "Resource": { + "id": "Resource", + "path": "test-kinesis-stream-action-stack/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/aws-iam.CfnRole", + "version": "0.0.0" + } + }, + "DefaultPolicy": { + "id": "DefaultPolicy", + "path": "test-kinesis-stream-action-stack/TopicRule/TopicRuleActionRole/DefaultPolicy", + "children": { + "Resource": { + "id": "Resource", + "path": "test-kinesis-stream-action-stack/TopicRule/TopicRuleActionRole/DefaultPolicy/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Policy", + "aws:cdk:cloudformation:props": { + "policyDocument": { + "Statement": [ + { + "Action": "dynamodb:PutItem", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyTable794EDED1", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "policyName": "TopicRuleTopicRuleActionRoleDefaultPolicy99ADD687", + "roles": [ + { + "Ref": "TopicRuleTopicRuleActionRole246C4F77" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.CfnPolicy", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.Policy", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.Role", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iot.TopicRule", + "version": "0.0.0" + } + }, + "MyTable": { + "id": "MyTable", + "path": "test-kinesis-stream-action-stack/MyTable", + "children": { + "Resource": { + "id": "Resource", + "path": "test-kinesis-stream-action-stack/MyTable/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::DynamoDB::Table", + "aws:cdk:cloudformation:props": { + "keySchema": [ + { + "attributeName": "hashKey", + "keyType": "HASH" + }, + { + "attributeName": "sortKey", + "keyType": "RANGE" + } + ], + "attributeDefinitions": [ + { + "attributeName": "hashKey", + "attributeType": "S" + }, + { + "attributeName": "sortKey", + "attributeType": "N" + } + ], + "provisionedThroughput": { + "readCapacityUnits": 1, + "writeCapacityUnits": 1 + }, + "tableName": "MyTable" + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-dynamodb.CfnTable", + "version": "0.0.0" + } + }, + "ScalingRole": { + "id": "ScalingRole", + "path": "test-kinesis-stream-action-stack/MyTable/ScalingRole", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-dynamodb.Table", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.test.ts b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.test.ts new file mode 100644 index 0000000000000..f4ddf926ed6f5 --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.test.ts @@ -0,0 +1,96 @@ +import { Template, Match } from '@aws-cdk/assertions'; +import * as dynamodb from '@aws-cdk/aws-dynamodb'; +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'; + +test('Default dynamoDBv2 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 table = dynamodb.Table.fromTableArn(stack, 'MyTable', 'arn:aws:dynamodb:xx-west-1:111122223333:table/my-table'); + + // WHEN + topicRule.addAction(new actions.DynamoDBv2PutItemAction(table)); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::IoT::TopicRule', { + TopicRulePayload: { + Actions: [ + { + DynamoDBv2: { + PutItem: { + TableName: 'my-table', + }, + 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: 'dynamodb:PutItem', + Effect: 'Allow', + Resource: 'arn:aws:dynamodb:xx-west-1:111122223333:table/my-table', + }, + ], + Version: '2012-10-17', + }, + PolicyName: 'MyTopicRuleTopicRuleActionRoleDefaultPolicy54A701F7', + Roles: [ + { Ref: 'MyTopicRuleTopicRuleActionRoleCE2D05DA' }, + ], + }); +}); + + +test('can set role', () => { + // 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 table = dynamodb.Table.fromTableArn(stack, 'MyTable', 'arn:aws:dynamodb:xx-west-1:111122223333:table/my-table'); + const role = iam.Role.fromRoleArn(stack, 'MyRole', 'arn:aws:iam::123456789012:role/ForTest'); + + // WHEN + topicRule.addAction(new actions.DynamoDBv2PutItemAction(table, { role })); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::IoT::TopicRule', { + TopicRulePayload: { + Actions: [ + Match.objectLike({ DynamoDBv2: { 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/dynamodb-v2/integ.dynamodb-put-item-action.expected.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-put-item-action.expected.json new file mode 100644 index 0000000000000..cbbbe10537bcb --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-put-item-action.expected.json @@ -0,0 +1,105 @@ +{ + "Resources": { + "TopicRule40A4EA44": { + "Type": "AWS::IoT::TopicRule", + "Properties": { + "TopicRulePayload": { + "Actions": [ + { + "DynamoDBv2": { + "PutItem": { + "TableName": { + "Ref": "MyTable794EDED1" + } + }, + "RoleArn": { + "Fn::GetAtt": [ + "TopicRuleTopicRuleActionRole246C4F77", + "Arn" + ] + } + } + } + ], + "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": "dynamodb:PutItem", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyTable794EDED1", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "TopicRuleTopicRuleActionRoleDefaultPolicy99ADD687", + "Roles": [ + { + "Ref": "TopicRuleTopicRuleActionRole246C4F77" + } + ] + } + }, + "MyTable794EDED1": { + "Type": "AWS::DynamoDB::Table", + "Properties": { + "KeySchema": [ + { + "AttributeName": "hashKey", + "KeyType": "HASH" + }, + { + "AttributeName": "sortKey", + "KeyType": "RANGE" + } + ], + "AttributeDefinitions": [ + { + "AttributeName": "hashKey", + "AttributeType": "S" + }, + { + "AttributeName": "sortKey", + "AttributeType": "N" + } + ], + "ProvisionedThroughput": { + "ReadCapacityUnits": 1, + "WriteCapacityUnits": 1 + }, + "TableName": "MyTable" + }, + "UpdateReplacePolicy": "Retain", + "DeletionPolicy": "Retain" + } + } + } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts new file mode 100644 index 0000000000000..be2349e06ae6d --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts @@ -0,0 +1,40 @@ +import * as dynamodb from '@aws-cdk/aws-dynamodb'; +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'", + ), + }); + + const table_partition_key: dynamodb.Attribute = { + name: 'hashKey', + type: dynamodb.AttributeType.STRING, + }; + + const table_sort_key: dynamodb.Attribute = { + name: 'sortKey', + type: dynamodb.AttributeType.NUMBER, + }; + + const table = new dynamodb.Table(this, 'MyTable', { + tableName: 'MyTable', + readCapacity: 1, + writeCapacity: 1, + partitionKey: table_partition_key, + sortKey: table_sort_key, + }); + + topicRule.addAction(new actions.DynamoDBv2PutItemAction(table)); + } +} + +const app = new cdk.App(); +new TestStack(app, 'test-kinesis-stream-action-stack'); +app.synth(); diff --git a/packages/aws-cdk-lib/package.json b/packages/aws-cdk-lib/package.json index d6593f26f7612..65db1c4b95735 100644 --- a/packages/aws-cdk-lib/package.json +++ b/packages/aws-cdk-lib/package.json @@ -504,6 +504,7 @@ "./aws-iotfleethub": "./aws-iotfleethub/index.js", "./aws-iotsitewise": "./aws-iotsitewise/index.js", "./aws-iotthingsgraph": "./aws-iotthingsgraph/index.js", + "./aws-iottwinmaker": "./aws-iottwinmaker/index.js", "./aws-iotwireless": "./aws-iotwireless/index.js", "./aws-ivs": "./aws-ivs/index.js", "./aws-kafkaconnect": "./aws-kafkaconnect/index.js", @@ -535,6 +536,7 @@ "./aws-medialive": "./aws-medialive/index.js", "./aws-mediapackage": "./aws-mediapackage/index.js", "./aws-mediastore": "./aws-mediastore/index.js", + "./aws-mediatailor": "./aws-mediatailor/index.js", "./aws-memorydb": "./aws-memorydb/index.js", "./aws-msk": "./aws-msk/index.js", "./aws-mwaa": "./aws-mwaa/index.js", From 2b5e27f1d91f864b1544a7d0b1d3856616297cb8 Mon Sep 17 00:00:00 2001 From: bobveringa Date: Mon, 2 May 2022 22:57:52 +0000 Subject: [PATCH 02/14] Update readme Add dynamoDB example to readme and update list. --- packages/@aws-cdk/aws-iot-actions/README.md | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/packages/@aws-cdk/aws-iot-actions/README.md b/packages/@aws-cdk/aws-iot-actions/README.md index 088fda5f3e5b8..7928c104845a4 100644 --- a/packages/@aws-cdk/aws-iot-actions/README.md +++ b/packages/@aws-cdk/aws-iot-actions/README.md @@ -31,6 +31,7 @@ Currently supported are: - Put records to Kinesis Data Firehose stream - Send messages to SQS queues - Publish messages on SNS topics +- Write messages into columns of DynamoDB ## Republish a message to another MQTT topic @@ -278,3 +279,40 @@ const topicRule = new iot.TopicRule(this, 'TopicRule', { ], }); ``` + +## Write attributes of a message to DynamoDB + +The code snippet below creates an AWS IoT rule that writes all or part of an +MQTT message to DynamoDB using the DynamoDBv2 action. + +```ts +import * as dynamodb from '@aws-cdk/aws-dynamodb'; + +const topicRule = new iot.TopicRule(this, 'TopicRule', { + sql: iot.IotSql.fromStringAsVer20160323( + "SELECT * FROM 'device/+/data'", + ), + actions: [ + new actions.DynamoDBv2PutItemAction(table) + ], +}); + +const table_partition_key: dynamodb.Attribute = { + name: 'hashKey', + type: dynamodb.AttributeType.STRING, +}; + +const table_sort_key: dynamodb.Attribute = { + name: 'sortKey', + type: dynamodb.AttributeType.NUMBER, +}; + +const table = new dynamodb.Table(this, 'MyTable', { + tableName: 'MyTable', + readCapacity: 1, + writeCapacity: 1, + partitionKey: table_partition_key, + sortKey: table_sort_key, +}); + +``` From 3ba08b889f85c67b7046c481d14ebb794476f5de Mon Sep 17 00:00:00 2001 From: bobveringa Date: Mon, 2 May 2022 23:05:15 +0000 Subject: [PATCH 03/14] Update readme Reorder items so that the example works as intended. --- packages/@aws-cdk/aws-iot-actions/README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/@aws-cdk/aws-iot-actions/README.md b/packages/@aws-cdk/aws-iot-actions/README.md index 7928c104845a4..5142ff5703c0b 100644 --- a/packages/@aws-cdk/aws-iot-actions/README.md +++ b/packages/@aws-cdk/aws-iot-actions/README.md @@ -288,15 +288,6 @@ MQTT message to DynamoDB using the DynamoDBv2 action. ```ts import * as dynamodb from '@aws-cdk/aws-dynamodb'; -const topicRule = new iot.TopicRule(this, 'TopicRule', { - sql: iot.IotSql.fromStringAsVer20160323( - "SELECT * FROM 'device/+/data'", - ), - actions: [ - new actions.DynamoDBv2PutItemAction(table) - ], -}); - const table_partition_key: dynamodb.Attribute = { name: 'hashKey', type: dynamodb.AttributeType.STRING, @@ -315,4 +306,13 @@ const table = new dynamodb.Table(this, 'MyTable', { sortKey: table_sort_key, }); +const topicRule = new iot.TopicRule(this, 'TopicRule', { + sql: iot.IotSql.fromStringAsVer20160323( + "SELECT * FROM 'device/+/data'", + ), + actions: [ + new actions.DynamoDBv2PutItemAction(table) + ], +}); + ``` From 290b6121299f1ce2603f38a1df3b8a20d6724deb Mon Sep 17 00:00:00 2001 From: Bob <6730660+bobveringa@users.noreply.github.com> Date: Fri, 6 May 2022 10:04:56 +0200 Subject: [PATCH 04/14] Update packages/@aws-cdk/aws-iot-actions/README.md Co-authored-by: Tatsuya Yamamoto --- packages/@aws-cdk/aws-iot-actions/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-iot-actions/README.md b/packages/@aws-cdk/aws-iot-actions/README.md index 5142ff5703c0b..9ff3cb41587c2 100644 --- a/packages/@aws-cdk/aws-iot-actions/README.md +++ b/packages/@aws-cdk/aws-iot-actions/README.md @@ -288,12 +288,12 @@ MQTT message to DynamoDB using the DynamoDBv2 action. ```ts import * as dynamodb from '@aws-cdk/aws-dynamodb'; -const table_partition_key: dynamodb.Attribute = { +const tablePartitionKey: dynamodb.Attribute = { name: 'hashKey', type: dynamodb.AttributeType.STRING, }; -const table_sort_key: dynamodb.Attribute = { +const tableSortKey: dynamodb.Attribute = { name: 'sortKey', type: dynamodb.AttributeType.NUMBER, }; @@ -302,8 +302,8 @@ const table = new dynamodb.Table(this, 'MyTable', { tableName: 'MyTable', readCapacity: 1, writeCapacity: 1, - partitionKey: table_partition_key, - sortKey: table_sort_key, + partitionKey: tablePartitionKey, + sortKey: tableSortKey, }); const topicRule = new iot.TopicRule(this, 'TopicRule', { From a50e3bb988a41020915b3feae1a96cde183457e5 Mon Sep 17 00:00:00 2001 From: Bob <6730660+bobveringa@users.noreply.github.com> Date: Fri, 6 May 2022 10:05:11 +0200 Subject: [PATCH 05/14] Update packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts Co-authored-by: Tatsuya Yamamoto --- .../test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts index be2349e06ae6d..a3bdaa3490adb 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts @@ -13,12 +13,12 @@ class TestStack extends cdk.Stack { ), }); - const table_partition_key: dynamodb.Attribute = { + const tablePartitionKey: dynamodb.Attribute = { name: 'hashKey', type: dynamodb.AttributeType.STRING, }; - const table_sort_key: dynamodb.Attribute = { + const tableSortKey: dynamodb.Attribute = { name: 'sortKey', type: dynamodb.AttributeType.NUMBER, }; @@ -27,8 +27,8 @@ class TestStack extends cdk.Stack { tableName: 'MyTable', readCapacity: 1, writeCapacity: 1, - partitionKey: table_partition_key, - sortKey: table_sort_key, + partitionKey: tablePartitionKey, + sortKey: tableSortKey, }); topicRule.addAction(new actions.DynamoDBv2PutItemAction(table)); From d3be03eba781165a5404a71b6d75cd3b2129b148 Mon Sep 17 00:00:00 2001 From: Bob <6730660+bobveringa@users.noreply.github.com> Date: Fri, 6 May 2022 10:05:23 +0200 Subject: [PATCH 06/14] Update packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts Co-authored-by: Tatsuya Yamamoto --- .../test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts index a3bdaa3490adb..77df3db0ce79d 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts @@ -36,5 +36,5 @@ class TestStack extends cdk.Stack { } const app = new cdk.App(); -new TestStack(app, 'test-kinesis-stream-action-stack'); +new TestStack(app, 'test-dynamo-d-bv2-put-item-action-stack'); app.synth(); From d6c4912cf6f8b38e21ebf0cbbdeb1f89da2437db Mon Sep 17 00:00:00 2001 From: bobveringa Date: Fri, 6 May 2022 08:25:45 +0000 Subject: [PATCH 07/14] Integrate code review feedback Integrate feedback from the review and re-run integration tests to validate no regressions have occurred. --- .../integ.json | 2 +- .../manifest.json | 16 ++++++------- ...d-bv2-put-item-action-stack.template.json} | 4 ++-- .../tree.json | 24 +++++++++---------- .../integ.dynamodb-v2-put-item-action.ts | 1 + 5 files changed, 24 insertions(+), 23 deletions(-) rename packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/{test-kinesis-stream-action-stack.template.json => test-dynamo-d-bv2-put-item-action-stack.template.json} (96%) diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/integ.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/integ.json index d2e5d9c2da04e..0a412a678b566 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/integ.json +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/integ.json @@ -3,7 +3,7 @@ "testCases": { "dynamodb-v2/integ.dynamodb-v2-put-item-action": { "stacks": [ - "test-kinesis-stream-action-stack" + "test-dynamo-d-bv2-put-item-action-stack" ], "diffAssets": false, "stackUpdateWorkflow": true diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/manifest.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/manifest.json index a78a3968b54de..b0faaa9a57e66 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/manifest.json @@ -7,33 +7,33 @@ "file": "tree.json" } }, - "test-kinesis-stream-action-stack": { + "test-dynamo-d-bv2-put-item-action-stack": { "type": "aws:cloudformation:stack", "environment": "aws://unknown-account/unknown-region", "properties": { - "templateFile": "test-kinesis-stream-action-stack.template.json", + "templateFile": "test-dynamo-d-bv2-put-item-action-stack.template.json", "validateOnSynth": false }, "metadata": { - "/test-kinesis-stream-action-stack/TopicRule/Resource": [ + "/test-dynamo-d-bv2-put-item-action-stack/TopicRule/Resource": [ { "type": "aws:cdk:logicalId", "data": "TopicRule40A4EA44" } ], - "/test-kinesis-stream-action-stack/TopicRule/TopicRuleActionRole/Resource": [ + "/test-dynamo-d-bv2-put-item-action-stack/TopicRule/TopicRuleActionRole/Resource": [ { "type": "aws:cdk:logicalId", "data": "TopicRuleTopicRuleActionRole246C4F77" } ], - "/test-kinesis-stream-action-stack/TopicRule/TopicRuleActionRole/DefaultPolicy/Resource": [ + "/test-dynamo-d-bv2-put-item-action-stack/TopicRule/TopicRuleActionRole/DefaultPolicy/Resource": [ { "type": "aws:cdk:logicalId", "data": "TopicRuleTopicRuleActionRoleDefaultPolicy99ADD687" } ], - "/test-kinesis-stream-action-stack/MyTable": [ + "/test-dynamo-d-bv2-put-item-action-stack/MyTable": [ { "type": "aws:cdk:hasPhysicalName", "data": { @@ -41,14 +41,14 @@ } } ], - "/test-kinesis-stream-action-stack/MyTable/Resource": [ + "/test-dynamo-d-bv2-put-item-action-stack/MyTable/Resource": [ { "type": "aws:cdk:logicalId", "data": "MyTable794EDED1" } ] }, - "displayName": "test-kinesis-stream-action-stack" + "displayName": "test-dynamo-d-bv2-put-item-action-stack" } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/test-kinesis-stream-action-stack.template.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/test-dynamo-d-bv2-put-item-action-stack.template.json similarity index 96% rename from packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/test-kinesis-stream-action-stack.template.json rename to packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/test-dynamo-d-bv2-put-item-action-stack.template.json index ca48050d2ceb4..d7fa86d112450 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/test-kinesis-stream-action-stack.template.json +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/test-dynamo-d-bv2-put-item-action-stack.template.json @@ -98,8 +98,8 @@ }, "TableName": "MyTable" }, - "UpdateReplacePolicy": "Retain", - "DeletionPolicy": "Retain" + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/tree.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/tree.json index 9ef9a3e79ee29..9f3852152d779 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/tree.json +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/tree.json @@ -12,17 +12,17 @@ "version": "0.0.0" } }, - "test-kinesis-stream-action-stack": { - "id": "test-kinesis-stream-action-stack", - "path": "test-kinesis-stream-action-stack", + "test-dynamo-d-bv2-put-item-action-stack": { + "id": "test-dynamo-d-bv2-put-item-action-stack", + "path": "test-dynamo-d-bv2-put-item-action-stack", "children": { "TopicRule": { "id": "TopicRule", - "path": "test-kinesis-stream-action-stack/TopicRule", + "path": "test-dynamo-d-bv2-put-item-action-stack/TopicRule", "children": { "Resource": { "id": "Resource", - "path": "test-kinesis-stream-action-stack/TopicRule/Resource", + "path": "test-dynamo-d-bv2-put-item-action-stack/TopicRule/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::IoT::TopicRule", "aws:cdk:cloudformation:props": { @@ -56,11 +56,11 @@ }, "TopicRuleActionRole": { "id": "TopicRuleActionRole", - "path": "test-kinesis-stream-action-stack/TopicRule/TopicRuleActionRole", + "path": "test-dynamo-d-bv2-put-item-action-stack/TopicRule/TopicRuleActionRole", "children": { "Resource": { "id": "Resource", - "path": "test-kinesis-stream-action-stack/TopicRule/TopicRuleActionRole/Resource", + "path": "test-dynamo-d-bv2-put-item-action-stack/TopicRule/TopicRuleActionRole/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::IAM::Role", "aws:cdk:cloudformation:props": { @@ -85,11 +85,11 @@ }, "DefaultPolicy": { "id": "DefaultPolicy", - "path": "test-kinesis-stream-action-stack/TopicRule/TopicRuleActionRole/DefaultPolicy", + "path": "test-dynamo-d-bv2-put-item-action-stack/TopicRule/TopicRuleActionRole/DefaultPolicy", "children": { "Resource": { "id": "Resource", - "path": "test-kinesis-stream-action-stack/TopicRule/TopicRuleActionRole/DefaultPolicy/Resource", + "path": "test-dynamo-d-bv2-put-item-action-stack/TopicRule/TopicRuleActionRole/DefaultPolicy/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::IAM::Policy", "aws:cdk:cloudformation:props": { @@ -141,11 +141,11 @@ }, "MyTable": { "id": "MyTable", - "path": "test-kinesis-stream-action-stack/MyTable", + "path": "test-dynamo-d-bv2-put-item-action-stack/MyTable", "children": { "Resource": { "id": "Resource", - "path": "test-kinesis-stream-action-stack/MyTable/Resource", + "path": "test-dynamo-d-bv2-put-item-action-stack/MyTable/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::DynamoDB::Table", "aws:cdk:cloudformation:props": { @@ -183,7 +183,7 @@ }, "ScalingRole": { "id": "ScalingRole", - "path": "test-kinesis-stream-action-stack/MyTable/ScalingRole", + "path": "test-dynamo-d-bv2-put-item-action-stack/MyTable/ScalingRole", "constructInfo": { "fqn": "@aws-cdk/core.Resource", "version": "0.0.0" diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts index 77df3db0ce79d..e769ec2076c8d 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts @@ -29,6 +29,7 @@ class TestStack extends cdk.Stack { writeCapacity: 1, partitionKey: tablePartitionKey, sortKey: tableSortKey, + removalPolicy: cdk.RemovalPolicy.DESTROY, }); topicRule.addAction(new actions.DynamoDBv2PutItemAction(table)); From 90f4284ad62be463ab6da4971c0a31a354305880 Mon Sep 17 00:00:00 2001 From: Bob <6730660+bobveringa@users.noreply.github.com> Date: Sun, 24 Jul 2022 14:39:37 +0200 Subject: [PATCH 08/14] Apply suggestions from code review Co-authored-by: Tatsuya Yamamoto --- packages/@aws-cdk/aws-iot-actions/README.md | 1 - packages/@aws-cdk/aws-iot-actions/lib/dynamo-db-v2-put-item.ts | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-iot-actions/README.md b/packages/@aws-cdk/aws-iot-actions/README.md index 9ff3cb41587c2..c433051675854 100644 --- a/packages/@aws-cdk/aws-iot-actions/README.md +++ b/packages/@aws-cdk/aws-iot-actions/README.md @@ -314,5 +314,4 @@ const topicRule = new iot.TopicRule(this, 'TopicRule', { new actions.DynamoDBv2PutItemAction(table) ], }); - ``` diff --git a/packages/@aws-cdk/aws-iot-actions/lib/dynamo-db-v2-put-item.ts b/packages/@aws-cdk/aws-iot-actions/lib/dynamo-db-v2-put-item.ts index eeabe17c0579e..606ad3f0036f0 100644 --- a/packages/@aws-cdk/aws-iot-actions/lib/dynamo-db-v2-put-item.ts +++ b/packages/@aws-cdk/aws-iot-actions/lib/dynamo-db-v2-put-item.ts @@ -10,9 +10,8 @@ import { singletonActionRole } from './private/role'; export interface DynamoDBv2PutItemActionProps extends CommonActionProps { } - /** - * The action to put the record from an MQTT message to the Kinesis Data Firehose stream. + * The action to put the record from an MQTT message to the DynamoDB table. */ export class DynamoDBv2PutItemAction implements iot.IAction { private readonly role?: iam.IRole; From cac341484edef0e80c7430d928d38d30c66562d2 Mon Sep 17 00:00:00 2001 From: Bob <6730660+bobveringa@users.noreply.github.com> Date: Sun, 24 Jul 2022 14:40:11 +0200 Subject: [PATCH 09/14] Update packages/@aws-cdk/aws-iot-actions/README.md Co-authored-by: Tatsuya Yamamoto --- packages/@aws-cdk/aws-iot-actions/README.md | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/packages/@aws-cdk/aws-iot-actions/README.md b/packages/@aws-cdk/aws-iot-actions/README.md index c433051675854..2572003a0fab7 100644 --- a/packages/@aws-cdk/aws-iot-actions/README.md +++ b/packages/@aws-cdk/aws-iot-actions/README.md @@ -288,23 +288,7 @@ MQTT message to DynamoDB using the DynamoDBv2 action. ```ts import * as dynamodb from '@aws-cdk/aws-dynamodb'; -const tablePartitionKey: dynamodb.Attribute = { - name: 'hashKey', - type: dynamodb.AttributeType.STRING, -}; - -const tableSortKey: dynamodb.Attribute = { - name: 'sortKey', - type: dynamodb.AttributeType.NUMBER, -}; - -const table = new dynamodb.Table(this, 'MyTable', { - tableName: 'MyTable', - readCapacity: 1, - writeCapacity: 1, - partitionKey: tablePartitionKey, - sortKey: tableSortKey, -}); +declare const table: dynamodb.Table; const topicRule = new iot.TopicRule(this, 'TopicRule', { sql: iot.IotSql.fromStringAsVer20160323( From c6ae40916f53e973d8810b4a1d890d632285dbc4 Mon Sep 17 00:00:00 2001 From: bobveringa Date: Sun, 24 Jul 2022 12:43:47 +0000 Subject: [PATCH 10/14] Renamed file to follow AWS convention --- .../{dynamo-db-v2-put-item.ts => dynamodbv2-put-item-action.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/@aws-cdk/aws-iot-actions/lib/{dynamo-db-v2-put-item.ts => dynamodbv2-put-item-action.ts} (100%) diff --git a/packages/@aws-cdk/aws-iot-actions/lib/dynamo-db-v2-put-item.ts b/packages/@aws-cdk/aws-iot-actions/lib/dynamodbv2-put-item-action.ts similarity index 100% rename from packages/@aws-cdk/aws-iot-actions/lib/dynamo-db-v2-put-item.ts rename to packages/@aws-cdk/aws-iot-actions/lib/dynamodbv2-put-item-action.ts From c9db00d7fda3b6e3b955fcc1b6e6eeeb1ad338da Mon Sep 17 00:00:00 2001 From: Kendra Neil <53584728+TheRealAmazonKendra@users.noreply.github.com> Date: Tue, 26 Jul 2022 14:39:32 -0700 Subject: [PATCH 11/14] fix export --- packages/@aws-cdk/aws-iot-actions/lib/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-iot-actions/lib/index.ts b/packages/@aws-cdk/aws-iot-actions/lib/index.ts index 7e62efee286a1..7074ca743082c 100644 --- a/packages/@aws-cdk/aws-iot-actions/lib/index.ts +++ b/packages/@aws-cdk/aws-iot-actions/lib/index.ts @@ -2,7 +2,7 @@ export * from './cloudwatch-logs-action'; export * from './cloudwatch-put-metric-action'; export * from './cloudwatch-set-alarm-state-action'; export * from './common-action-props'; -export * from './dynamo-db-v2-put-item'; +export * from './dynamo-db-v2-put-item-action'; export * from './firehose-put-record-action'; export * from './iot-republish-action'; export * from './kinesis-put-record-action'; From 6d2d87a61eacea818d03c0b6efdb741a6ea38fca Mon Sep 17 00:00:00 2001 From: Kendra Neil <53584728+TheRealAmazonKendra@users.noreply.github.com> Date: Tue, 26 Jul 2022 14:40:49 -0700 Subject: [PATCH 12/14] fix export name --- packages/@aws-cdk/aws-iot-actions/lib/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-iot-actions/lib/index.ts b/packages/@aws-cdk/aws-iot-actions/lib/index.ts index 7074ca743082c..91dd24ac32cd1 100644 --- a/packages/@aws-cdk/aws-iot-actions/lib/index.ts +++ b/packages/@aws-cdk/aws-iot-actions/lib/index.ts @@ -2,7 +2,7 @@ export * from './cloudwatch-logs-action'; export * from './cloudwatch-put-metric-action'; export * from './cloudwatch-set-alarm-state-action'; export * from './common-action-props'; -export * from './dynamo-db-v2-put-item-action'; +export * from './dynamodbv2-put-item-action'; export * from './firehose-put-record-action'; export * from './iot-republish-action'; export * from './kinesis-put-record-action'; From c802989a5f0cda17b9773a5cc39043aa8fb68abf Mon Sep 17 00:00:00 2001 From: bobveringa Date: Tue, 2 Aug 2022 12:07:28 +0000 Subject: [PATCH 13/14] Changed filenames to match formatting and added IntegTest construct --- .../dynamodbv2-put-item-action.integ.snapshot}/cdk.out | 0 .../dynamodbv2-put-item-action.integ.snapshot}/integ.json | 0 .../manifest.json | 0 .../test-dynamo-d-bv2-put-item-action-stack.template.json | 0 .../dynamodbv2-put-item-action.integ.snapshot}/tree.json | 0 .../dynamodbv2-put-item-action.test.ts} | 0 .../integ.dynamodbv2-put-item-action.expected.json} | 0 .../integ.dynamodbv2-put-item-action.ts} | 8 +++++++- 8 files changed, 7 insertions(+), 1 deletion(-) rename packages/@aws-cdk/aws-iot-actions/test/{dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot => dynamodbv2/dynamodbv2-put-item-action.integ.snapshot}/cdk.out (100%) rename packages/@aws-cdk/aws-iot-actions/test/{dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot => dynamodbv2/dynamodbv2-put-item-action.integ.snapshot}/integ.json (100%) rename packages/@aws-cdk/aws-iot-actions/test/{dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot => dynamodbv2/dynamodbv2-put-item-action.integ.snapshot}/manifest.json (100%) rename packages/@aws-cdk/aws-iot-actions/test/{dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot => dynamodbv2/dynamodbv2-put-item-action.integ.snapshot}/test-dynamo-d-bv2-put-item-action-stack.template.json (100%) rename packages/@aws-cdk/aws-iot-actions/test/{dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot => dynamodbv2/dynamodbv2-put-item-action.integ.snapshot}/tree.json (100%) rename packages/@aws-cdk/aws-iot-actions/test/{dynamodb-v2/dynamodb-v2-put-item-action.test.ts => dynamodbv2/dynamodbv2-put-item-action.test.ts} (100%) rename packages/@aws-cdk/aws-iot-actions/test/{dynamodb-v2/integ.dynamodb-put-item-action.expected.json => dynamodbv2/integ.dynamodbv2-put-item-action.expected.json} (100%) rename packages/@aws-cdk/aws-iot-actions/test/{dynamodb-v2/integ.dynamodb-v2-put-item-action.ts => dynamodbv2/integ.dynamodbv2-put-item-action.ts} (84%) diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/cdk.out b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/cdk.out similarity index 100% rename from packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/cdk.out rename to packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/cdk.out diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/integ.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/integ.json similarity index 100% rename from packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/integ.json rename to packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/integ.json diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/manifest.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/manifest.json similarity index 100% rename from packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/manifest.json rename to packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/manifest.json diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/test-dynamo-d-bv2-put-item-action-stack.template.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/test-dynamo-d-bv2-put-item-action-stack.template.json similarity index 100% rename from packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/test-dynamo-d-bv2-put-item-action-stack.template.json rename to packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/test-dynamo-d-bv2-put-item-action-stack.template.json diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/tree.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/tree.json similarity index 100% rename from packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.integ.snapshot/tree.json rename to packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/tree.json diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.test.ts b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.test.ts similarity index 100% rename from packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/dynamodb-v2-put-item-action.test.ts rename to packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.test.ts diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-put-item-action.expected.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/integ.dynamodbv2-put-item-action.expected.json similarity index 100% rename from packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-put-item-action.expected.json rename to packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/integ.dynamodbv2-put-item-action.expected.json diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/integ.dynamodbv2-put-item-action.ts similarity index 84% rename from packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts rename to packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/integ.dynamodbv2-put-item-action.ts index e769ec2076c8d..ca6c605ff3ad8 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/dynamodb-v2/integ.dynamodb-v2-put-item-action.ts +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/integ.dynamodbv2-put-item-action.ts @@ -2,6 +2,7 @@ import * as dynamodb from '@aws-cdk/aws-dynamodb'; import * as iot from '@aws-cdk/aws-iot'; import * as cdk from '@aws-cdk/core'; import * as actions from '../../lib'; +import * as integ from '@aws-cdk/integ-tests'; class TestStack extends cdk.Stack { constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { @@ -37,5 +38,10 @@ class TestStack extends cdk.Stack { } const app = new cdk.App(); -new TestStack(app, 'test-dynamo-d-bv2-put-item-action-stack'); +const stack = new TestStack(app, 'test-dynamo-d-bv2-put-item-action-stack'); + +new integ.IntegTest(app, 'dynamodbv2-integtest', { + testCases: [stack], +}); + app.synth(); From 8b0f3eaf009d2846ecd506fa8ab27f0d70abe92f Mon Sep 17 00:00:00 2001 From: Kendra Neil <53584728+TheRealAmazonKendra@users.noreply.github.com> Date: Tue, 2 Aug 2022 16:11:03 -0700 Subject: [PATCH 14/14] update tests --- .../aws-iot-actions/package-lock.json | 173 ++++++++++++++++++ .../@aws-cdk/aws-iot-actions/package.json | 1 + .../cdk.out | 2 +- ...aultTestDeployAssertEF9A9A37.template.json | 1 + .../integ.json | 13 +- .../manifest.json | 27 ++- ...odbv2-put-item-action-stack.template.json} | 0 .../tree.json | 64 +++++-- ...g.dynamodbv2-put-item-action.expected.json | 105 ----------- .../integ.dynamodbv2-put-item-action.ts | 64 +++---- 10 files changed, 278 insertions(+), 172 deletions(-) create mode 100644 packages/@aws-cdk/aws-iot-actions/package-lock.json create mode 100644 packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/dynamodbv2integtestDefaultTestDeployAssertEF9A9A37.template.json rename packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/{test-dynamo-d-bv2-put-item-action-stack.template.json => test-dynamodbv2-put-item-action-stack.template.json} (100%) delete mode 100644 packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/integ.dynamodbv2-put-item-action.expected.json diff --git a/packages/@aws-cdk/aws-iot-actions/package-lock.json b/packages/@aws-cdk/aws-iot-actions/package-lock.json new file mode 100644 index 0000000000000..094a8191aafc5 --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions/package-lock.json @@ -0,0 +1,173 @@ +{ + "name": "@aws-cdk/aws-iot-actions", + "version": "0.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@aws-cdk/cloud-assembly-schema": { + "version": "1.166.1", + "resolved": "https://registry.npmjs.org/@aws-cdk/cloud-assembly-schema/-/cloud-assembly-schema-1.166.1.tgz", + "integrity": "sha512-QL8IKpaUngtqQipLO6/7uvbR7HE8CTr2z3JLKcLjofountigs6l4VdL8wR6XMbzZ18DaOJ6iLWHGpbT4BBoHPg==", + "requires": { + "jsonschema": "^1.4.1", + "semver": "^7.3.7" + }, + "dependencies": { + "jsonschema": { + "version": "1.4.1", + "bundled": true + }, + "lru-cache": { + "version": "6.0.0", + "bundled": true, + "requires": { + "yallist": "^4.0.0" + } + }, + "semver": { + "version": "7.3.7", + "bundled": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, + "yallist": { + "version": "4.0.0", + "bundled": true + } + } + }, + "@aws-cdk/cx-api": { + "version": "1.166.1", + "resolved": "https://registry.npmjs.org/@aws-cdk/cx-api/-/cx-api-1.166.1.tgz", + "integrity": "sha512-cCsRe8wRGVhGaKFcW2l4b2LInzc9FeDsoaRTRreT3I+MxYyCAYlwWmx0RYoLg6r5eq6TD9PLAbOcCC6Y46CZ1g==", + "requires": { + "@aws-cdk/cloud-assembly-schema": "1.166.1", + "semver": "^7.3.7" + }, + "dependencies": { + "lru-cache": { + "version": "6.0.0", + "bundled": true, + "requires": { + "yallist": "^4.0.0" + } + }, + "semver": { + "version": "7.3.7", + "bundled": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, + "yallist": { + "version": "4.0.0", + "bundled": true + } + } + }, + "@aws-cdk/integ-tests": { + "version": "1.166.1", + "resolved": "https://registry.npmjs.org/@aws-cdk/integ-tests/-/integ-tests-1.166.1.tgz", + "integrity": "sha512-x+KHKQDjKYbqTEUnTcbQa7Ubqu25N3/6PTeXpYs2staBB0HQPySjwbY87I6Lxpi1AexlJb+YhwfBofC7B/qoBQ==", + "requires": { + "@aws-cdk/cloud-assembly-schema": "1.166.1", + "@aws-cdk/core": "1.166.1", + "constructs": "^3.3.69" + }, + "dependencies": { + "@aws-cdk/core": { + "version": "1.166.1", + "resolved": "https://registry.npmjs.org/@aws-cdk/core/-/core-1.166.1.tgz", + "integrity": "sha512-C0xNgePI1o6+RJqiXSG3RgiQu7q9uKf56QxeRgvCLsgDDrS/DBZFe7erAC/cO6R7mxhqyOOIWJSHuCdUWPmkqg==", + "requires": { + "@aws-cdk/cloud-assembly-schema": "1.166.1", + "@aws-cdk/cx-api": "1.166.1", + "@aws-cdk/region-info": "1.166.1", + "@balena/dockerignore": "^1.0.2", + "constructs": "^3.3.69", + "fs-extra": "^9.1.0", + "ignore": "^5.2.0", + "minimatch": "^3.1.2" + }, + "dependencies": { + "@balena/dockerignore": { + "version": "1.0.2", + "bundled": true + }, + "at-least-node": { + "version": "1.0.0", + "bundled": true + }, + "balanced-match": { + "version": "1.0.2", + "bundled": true + }, + "brace-expansion": { + "version": "1.1.11", + "bundled": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "concat-map": { + "version": "0.0.1", + "bundled": true + }, + "fs-extra": { + "version": "9.1.0", + "bundled": true, + "requires": { + "at-least-node": "^1.0.0", + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + } + }, + "graceful-fs": { + "version": "4.2.10", + "bundled": true + }, + "ignore": { + "version": "5.2.0", + "bundled": true + }, + "jsonfile": { + "version": "6.1.0", + "bundled": true, + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^2.0.0" + } + }, + "minimatch": { + "version": "3.1.2", + "bundled": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "universalify": { + "version": "2.0.0", + "bundled": true + } + } + }, + "constructs": { + "version": "3.4.57", + "resolved": "https://registry.npmjs.org/constructs/-/constructs-3.4.57.tgz", + "integrity": "sha512-jQyF6jFUJFqew13gDMZ9G8TkgFIJ7jMIG56FX9i3j/4pfGHrT+zwu6C95uuFIrBveC2RctxuDup23xBzs/XgUA==" + } + } + }, + "@aws-cdk/region-info": { + "version": "1.166.1", + "resolved": "https://registry.npmjs.org/@aws-cdk/region-info/-/region-info-1.166.1.tgz", + "integrity": "sha512-yxjMjXNhG+Iqo04P1U0JNBGeR3kfDe3Ecc72ywuxi+QH/bhCEGnf+783BjYqXHWh4olTwZbMYQ/BcsOO0Dchkw==" + }, + "case": { + "version": "1.6.3" + } + } +} diff --git a/packages/@aws-cdk/aws-iot-actions/package.json b/packages/@aws-cdk/aws-iot-actions/package.json index 61bbd967d3ab9..44b052ec6db66 100644 --- a/packages/@aws-cdk/aws-iot-actions/package.json +++ b/packages/@aws-cdk/aws-iot-actions/package.json @@ -81,6 +81,7 @@ "@aws-cdk/aws-kinesisfirehose-destinations": "0.0.0", "@aws-cdk/cdk-build-tools": "0.0.0", "@aws-cdk/integ-runner": "0.0.0", + "@aws-cdk/integ-tests": "0.0.0", "@aws-cdk/pkglint": "0.0.0", "@types/jest": "^27.5.2", "jest": "^27.5.1", diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/cdk.out b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/cdk.out index 2efc89439fab8..588d7b269d34f 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/cdk.out +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/cdk.out @@ -1 +1 @@ -{"version":"18.0.0"} \ No newline at end of file +{"version":"20.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/dynamodbv2integtestDefaultTestDeployAssertEF9A9A37.template.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/dynamodbv2integtestDefaultTestDeployAssertEF9A9A37.template.json new file mode 100644 index 0000000000000..9e26dfeeb6e64 --- /dev/null +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/dynamodbv2integtestDefaultTestDeployAssertEF9A9A37.template.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/integ.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/integ.json index 0a412a678b566..c30fa81cf3bd9 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/integ.json +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/integ.json @@ -1,14 +1,11 @@ { - "version": "18.0.0", + "version": "20.0.0", "testCases": { - "dynamodb-v2/integ.dynamodb-v2-put-item-action": { + "dynamodbv2-integtest/DefaultTest": { "stacks": [ - "test-dynamo-d-bv2-put-item-action-stack" + "test-dynamodbv2-put-item-action-stack" ], - "diffAssets": false, - "stackUpdateWorkflow": true + "assertionStack": "dynamodbv2integtestDefaultTestDeployAssertEF9A9A37" } - }, - "synthContext": {}, - "enableLookups": false + } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/manifest.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/manifest.json index b0faaa9a57e66..50a2778c1a195 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/manifest.json @@ -1,5 +1,5 @@ { - "version": "18.0.0", + "version": "20.0.0", "artifacts": { "Tree": { "type": "cdk:tree", @@ -7,33 +7,33 @@ "file": "tree.json" } }, - "test-dynamo-d-bv2-put-item-action-stack": { + "test-dynamodbv2-put-item-action-stack": { "type": "aws:cloudformation:stack", "environment": "aws://unknown-account/unknown-region", "properties": { - "templateFile": "test-dynamo-d-bv2-put-item-action-stack.template.json", + "templateFile": "test-dynamodbv2-put-item-action-stack.template.json", "validateOnSynth": false }, "metadata": { - "/test-dynamo-d-bv2-put-item-action-stack/TopicRule/Resource": [ + "/test-dynamodbv2-put-item-action-stack/TopicRule/Resource": [ { "type": "aws:cdk:logicalId", "data": "TopicRule40A4EA44" } ], - "/test-dynamo-d-bv2-put-item-action-stack/TopicRule/TopicRuleActionRole/Resource": [ + "/test-dynamodbv2-put-item-action-stack/TopicRule/TopicRuleActionRole/Resource": [ { "type": "aws:cdk:logicalId", "data": "TopicRuleTopicRuleActionRole246C4F77" } ], - "/test-dynamo-d-bv2-put-item-action-stack/TopicRule/TopicRuleActionRole/DefaultPolicy/Resource": [ + "/test-dynamodbv2-put-item-action-stack/TopicRule/TopicRuleActionRole/DefaultPolicy/Resource": [ { "type": "aws:cdk:logicalId", "data": "TopicRuleTopicRuleActionRoleDefaultPolicy99ADD687" } ], - "/test-dynamo-d-bv2-put-item-action-stack/MyTable": [ + "/test-dynamodbv2-put-item-action-stack/MyTable": [ { "type": "aws:cdk:hasPhysicalName", "data": { @@ -41,14 +41,23 @@ } } ], - "/test-dynamo-d-bv2-put-item-action-stack/MyTable/Resource": [ + "/test-dynamodbv2-put-item-action-stack/MyTable/Resource": [ { "type": "aws:cdk:logicalId", "data": "MyTable794EDED1" } ] }, - "displayName": "test-dynamo-d-bv2-put-item-action-stack" + "displayName": "test-dynamodbv2-put-item-action-stack" + }, + "dynamodbv2integtestDefaultTestDeployAssertEF9A9A37": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "dynamodbv2integtestDefaultTestDeployAssertEF9A9A37.template.json", + "validateOnSynth": false + }, + "displayName": "dynamodbv2-integtest/DefaultTest/DeployAssert" } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/test-dynamo-d-bv2-put-item-action-stack.template.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/test-dynamodbv2-put-item-action-stack.template.json similarity index 100% rename from packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/test-dynamo-d-bv2-put-item-action-stack.template.json rename to packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/test-dynamodbv2-put-item-action-stack.template.json diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/tree.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/tree.json index 9f3852152d779..995b3a6a9f21f 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/tree.json +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/tree.json @@ -8,21 +8,21 @@ "id": "Tree", "path": "Tree", "constructInfo": { - "fqn": "@aws-cdk/core.Construct", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.1.63" } }, - "test-dynamo-d-bv2-put-item-action-stack": { - "id": "test-dynamo-d-bv2-put-item-action-stack", - "path": "test-dynamo-d-bv2-put-item-action-stack", + "test-dynamodbv2-put-item-action-stack": { + "id": "test-dynamodbv2-put-item-action-stack", + "path": "test-dynamodbv2-put-item-action-stack", "children": { "TopicRule": { "id": "TopicRule", - "path": "test-dynamo-d-bv2-put-item-action-stack/TopicRule", + "path": "test-dynamodbv2-put-item-action-stack/TopicRule", "children": { "Resource": { "id": "Resource", - "path": "test-dynamo-d-bv2-put-item-action-stack/TopicRule/Resource", + "path": "test-dynamodbv2-put-item-action-stack/TopicRule/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::IoT::TopicRule", "aws:cdk:cloudformation:props": { @@ -56,11 +56,11 @@ }, "TopicRuleActionRole": { "id": "TopicRuleActionRole", - "path": "test-dynamo-d-bv2-put-item-action-stack/TopicRule/TopicRuleActionRole", + "path": "test-dynamodbv2-put-item-action-stack/TopicRule/TopicRuleActionRole", "children": { "Resource": { "id": "Resource", - "path": "test-dynamo-d-bv2-put-item-action-stack/TopicRule/TopicRuleActionRole/Resource", + "path": "test-dynamodbv2-put-item-action-stack/TopicRule/TopicRuleActionRole/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::IAM::Role", "aws:cdk:cloudformation:props": { @@ -85,11 +85,11 @@ }, "DefaultPolicy": { "id": "DefaultPolicy", - "path": "test-dynamo-d-bv2-put-item-action-stack/TopicRule/TopicRuleActionRole/DefaultPolicy", + "path": "test-dynamodbv2-put-item-action-stack/TopicRule/TopicRuleActionRole/DefaultPolicy", "children": { "Resource": { "id": "Resource", - "path": "test-dynamo-d-bv2-put-item-action-stack/TopicRule/TopicRuleActionRole/DefaultPolicy/Resource", + "path": "test-dynamodbv2-put-item-action-stack/TopicRule/TopicRuleActionRole/DefaultPolicy/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::IAM::Policy", "aws:cdk:cloudformation:props": { @@ -141,11 +141,11 @@ }, "MyTable": { "id": "MyTable", - "path": "test-dynamo-d-bv2-put-item-action-stack/MyTable", + "path": "test-dynamodbv2-put-item-action-stack/MyTable", "children": { "Resource": { "id": "Resource", - "path": "test-dynamo-d-bv2-put-item-action-stack/MyTable/Resource", + "path": "test-dynamodbv2-put-item-action-stack/MyTable/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::DynamoDB::Table", "aws:cdk:cloudformation:props": { @@ -183,7 +183,7 @@ }, "ScalingRole": { "id": "ScalingRole", - "path": "test-dynamo-d-bv2-put-item-action-stack/MyTable/ScalingRole", + "path": "test-dynamodbv2-put-item-action-stack/MyTable/ScalingRole", "constructInfo": { "fqn": "@aws-cdk/core.Resource", "version": "0.0.0" @@ -200,6 +200,42 @@ "fqn": "@aws-cdk/core.Stack", "version": "0.0.0" } + }, + "dynamodbv2-integtest": { + "id": "dynamodbv2-integtest", + "path": "dynamodbv2-integtest", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "dynamodbv2-integtest/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "dynamodbv2-integtest/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.63" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "dynamodbv2-integtest/DefaultTest/DeployAssert", + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTest", + "version": "0.0.0" + } } }, "constructInfo": { diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/integ.dynamodbv2-put-item-action.expected.json b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/integ.dynamodbv2-put-item-action.expected.json deleted file mode 100644 index cbbbe10537bcb..0000000000000 --- a/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/integ.dynamodbv2-put-item-action.expected.json +++ /dev/null @@ -1,105 +0,0 @@ -{ - "Resources": { - "TopicRule40A4EA44": { - "Type": "AWS::IoT::TopicRule", - "Properties": { - "TopicRulePayload": { - "Actions": [ - { - "DynamoDBv2": { - "PutItem": { - "TableName": { - "Ref": "MyTable794EDED1" - } - }, - "RoleArn": { - "Fn::GetAtt": [ - "TopicRuleTopicRuleActionRole246C4F77", - "Arn" - ] - } - } - } - ], - "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": "dynamodb:PutItem", - "Effect": "Allow", - "Resource": { - "Fn::GetAtt": [ - "MyTable794EDED1", - "Arn" - ] - } - } - ], - "Version": "2012-10-17" - }, - "PolicyName": "TopicRuleTopicRuleActionRoleDefaultPolicy99ADD687", - "Roles": [ - { - "Ref": "TopicRuleTopicRuleActionRole246C4F77" - } - ] - } - }, - "MyTable794EDED1": { - "Type": "AWS::DynamoDB::Table", - "Properties": { - "KeySchema": [ - { - "AttributeName": "hashKey", - "KeyType": "HASH" - }, - { - "AttributeName": "sortKey", - "KeyType": "RANGE" - } - ], - "AttributeDefinitions": [ - { - "AttributeName": "hashKey", - "AttributeType": "S" - }, - { - "AttributeName": "sortKey", - "AttributeType": "N" - } - ], - "ProvisionedThroughput": { - "ReadCapacityUnits": 1, - "WriteCapacityUnits": 1 - }, - "TableName": "MyTable" - }, - "UpdateReplacePolicy": "Retain", - "DeletionPolicy": "Retain" - } - } - } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/integ.dynamodbv2-put-item-action.ts b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/integ.dynamodbv2-put-item-action.ts index ca6c605ff3ad8..1dc0e7c2eb509 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/integ.dynamodbv2-put-item-action.ts +++ b/packages/@aws-cdk/aws-iot-actions/test/dynamodbv2/integ.dynamodbv2-put-item-action.ts @@ -1,44 +1,38 @@ import * as dynamodb from '@aws-cdk/aws-dynamodb'; import * as iot from '@aws-cdk/aws-iot'; import * as cdk from '@aws-cdk/core'; -import * as actions from '../../lib'; import * as integ from '@aws-cdk/integ-tests'; - -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'", - ), - }); - - const tablePartitionKey: dynamodb.Attribute = { - name: 'hashKey', - type: dynamodb.AttributeType.STRING, - }; - - const tableSortKey: dynamodb.Attribute = { - name: 'sortKey', - type: dynamodb.AttributeType.NUMBER, - }; - - const table = new dynamodb.Table(this, 'MyTable', { - tableName: 'MyTable', - readCapacity: 1, - writeCapacity: 1, - partitionKey: tablePartitionKey, - sortKey: tableSortKey, - removalPolicy: cdk.RemovalPolicy.DESTROY, - }); - - topicRule.addAction(new actions.DynamoDBv2PutItemAction(table)); - } -} +import * as actions from '../../lib'; const app = new cdk.App(); -const stack = new TestStack(app, 'test-dynamo-d-bv2-put-item-action-stack'); +const stack = new cdk.Stack(app, 'test-dynamodbv2-put-item-action-stack'); + +const topicRule = new iot.TopicRule(stack, 'TopicRule', { + sql: iot.IotSql.fromStringAsVer20160323( + "SELECT * FROM 'device/+/data'", + ), +}); + +const tablePartitionKey: dynamodb.Attribute = { + name: 'hashKey', + type: dynamodb.AttributeType.STRING, +}; + +const tableSortKey: dynamodb.Attribute = { + name: 'sortKey', + type: dynamodb.AttributeType.NUMBER, +}; + +const table = new dynamodb.Table(stack, 'MyTable', { + tableName: 'MyTable', + readCapacity: 1, + writeCapacity: 1, + partitionKey: tablePartitionKey, + sortKey: tableSortKey, + removalPolicy: cdk.RemovalPolicy.DESTROY, +}); + +topicRule.addAction(new actions.DynamoDBv2PutItemAction(table)); new integ.IntegTest(app, 'dynamodbv2-integtest', { testCases: [stack],