-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(iot-actions): add support for DynamoDBv2 rule (#20171)
This merge request adds the dynamodbv2 IoT rule action as a new feature. This rule is useful for quickly logging device information into DynamoDB. Furthermore, it adds some other important functionality as IoT action. Closes #20162 ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
c33f1ea
commit a57dec3
Showing
13 changed files
with
806 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/@aws-cdk/aws-iot-actions/lib/dynamodbv2-put-item-action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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 DynamoDB table. | ||
*/ | ||
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, | ||
}, | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...aws-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/cdk.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"version":"20.0.0"} |
1 change: 1 addition & 0 deletions
1
...em-action.integ.snapshot/dynamodbv2integtestDefaultTestDeployAssertEF9A9A37.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
11 changes: 11 additions & 0 deletions
11
...-cdk/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/integ.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"version": "20.0.0", | ||
"testCases": { | ||
"dynamodbv2-integtest/DefaultTest": { | ||
"stacks": [ | ||
"test-dynamodbv2-put-item-action-stack" | ||
], | ||
"assertionStack": "dynamodbv2integtestDefaultTestDeployAssertEF9A9A37" | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...k/aws-iot-actions/test/dynamodbv2/dynamodbv2-put-item-action.integ.snapshot/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"version": "20.0.0", | ||
"artifacts": { | ||
"Tree": { | ||
"type": "cdk:tree", | ||
"properties": { | ||
"file": "tree.json" | ||
} | ||
}, | ||
"test-dynamodbv2-put-item-action-stack": { | ||
"type": "aws:cloudformation:stack", | ||
"environment": "aws://unknown-account/unknown-region", | ||
"properties": { | ||
"templateFile": "test-dynamodbv2-put-item-action-stack.template.json", | ||
"validateOnSynth": false | ||
}, | ||
"metadata": { | ||
"/test-dynamodbv2-put-item-action-stack/TopicRule/Resource": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "TopicRule40A4EA44" | ||
} | ||
], | ||
"/test-dynamodbv2-put-item-action-stack/TopicRule/TopicRuleActionRole/Resource": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "TopicRuleTopicRuleActionRole246C4F77" | ||
} | ||
], | ||
"/test-dynamodbv2-put-item-action-stack/TopicRule/TopicRuleActionRole/DefaultPolicy/Resource": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "TopicRuleTopicRuleActionRoleDefaultPolicy99ADD687" | ||
} | ||
], | ||
"/test-dynamodbv2-put-item-action-stack/MyTable": [ | ||
{ | ||
"type": "aws:cdk:hasPhysicalName", | ||
"data": { | ||
"Ref": "MyTable794EDED1" | ||
} | ||
} | ||
], | ||
"/test-dynamodbv2-put-item-action-stack/MyTable/Resource": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "MyTable794EDED1" | ||
} | ||
] | ||
}, | ||
"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" | ||
} | ||
} | ||
} |
Oops, something went wrong.