forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
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-alpha): open search action in IoT topic rule (aws#28748
) The CDK has no support to writes data to an Amazon OpenSearch Service via AWS IoT Rule. Adding the action that writes data to an Amazon OpenSearch Service to AWS IoT topic rule. OpenSearch action for IoT Topic Rule documentation is here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-iot-topicrule-opensearchaction.html. Closes aws#17702. Tested by deploying my own stack and confirmed that publishing a message to IoT topic rule will successfully write data to open search service. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
14 changed files
with
1,435 additions
and
16 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
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
59 changes: 59 additions & 0 deletions
59
packages/@aws-cdk/aws-iot-actions-alpha/lib/open-search-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,59 @@ | ||
import * as iam from 'aws-cdk-lib/aws-iam'; | ||
import * as iot from '@aws-cdk/aws-iot-alpha'; | ||
import * as opensearch from 'aws-cdk-lib/aws-opensearchservice'; | ||
import { CommonActionProps } from './common-action-props'; | ||
import { singletonActionRole } from './private/role'; | ||
|
||
/** | ||
* Configuration properties of an action for Open Search. | ||
*/ | ||
export interface OpenSearchActionProps extends CommonActionProps { | ||
/** | ||
* The unique identifier for the document you are storing. | ||
*/ | ||
readonly id: string; | ||
|
||
/** | ||
* The OpenSearch index where you want to store your data. | ||
*/ | ||
readonly index: string; | ||
|
||
/** | ||
* The type of document you are storing. | ||
*/ | ||
readonly type: string; | ||
} | ||
|
||
/** | ||
* The action to write data to an Amazon OpenSearch Service domain. | ||
*/ | ||
export class OpenSearchAction implements iot.IAction { | ||
constructor(private readonly domain: opensearch.Domain, private readonly props: OpenSearchActionProps) { | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public _bind(rule: iot.ITopicRule): iot.ActionConfig { | ||
const role = this.props.role ?? singletonActionRole(rule); | ||
|
||
// According to CloudFormation documentation, we only need 'es:ESHttpPut' permission | ||
// https://docs.aws.amazon.com/iot/latest/developerguide/opensearch-rule-action.html#opensearch-rule-action-requirements | ||
role.addToPrincipalPolicy(new iam.PolicyStatement({ | ||
actions: ['es:ESHttpPut'], | ||
resources: [this.domain.domainArn, `${this.domain.domainArn}/*`], | ||
})); | ||
|
||
return { | ||
configuration: { | ||
openSearch: { | ||
endpoint: `https://${this.domain.domainEndpoint}`, | ||
id: this.props.id, | ||
index: this.props.index, | ||
type: this.props.type, | ||
roleArn: role.roleArn, | ||
}, | ||
}, | ||
}; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
....snapshot/asset.1b474110b3f79050ba8693912584a5d5bac8c7e94d63afa8c73f1d087444e7cc/index.js
Large diffs are not rendered by default.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
...pensearch/integ.open-search-action.js.snapshot/aws-iot-opensearch-integ-stack.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.