Skip to content

Commit 24e460f

Browse files
committed
feat: support existing OS domain
1 parent 40c4fef commit 24e460f

File tree

12 files changed

+476
-285
lines changed

12 files changed

+476
-285
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ reported the issue. Please try to include as much information as you can. Detail
2323
## Contributing via Pull Requests
2424
Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
2525

26-
1. You are working against the latest source on the *main* branch.
26+
1. You are working against the latest source on the *master* branch.
2727
2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
2828
3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
2929

@@ -57,3 +57,5 @@ If you discover a potential security issue in this project we ask that you notif
5757
## Licensing
5858

5959
See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.
60+
61+
We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes.

LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7+
the Software, and to permit persons to whom the Software is furnished to do so.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
11+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
12+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
13+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15+
116
MIT No Attribution
217

318
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

README.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Near-Real Time Usage Anomaly Detection using OpenSearch
23

34
Detecting usage anomalies promptly is crucial because they can result in unforeseen charges. The Near-Real Time Usage Anomaly Detection solutions offers the capabilities to address this issue effectively.
@@ -37,7 +38,7 @@ The primary components of the solution's architecture are:
3738
- OpenSearch Dashboards access enabled by user authentication through the OpenSearchUser Cognito.
3839

3940
## Pre-requisites
40-
- [AWS Cloud Development Kit](https://docs.aws.amazon.com/cdk/v2/guide/home.html) version 2.69 or higher.
41+
- [AWS Cloud Development Kit](https://docs.aws.amazon.com/cdk/v2/guide/home.html) version 2.100.0.
4142
- All required libraries installed using python pip. Below commands are run locally from the root of the repository.
4243

4344
```
@@ -47,24 +48,37 @@ The primary components of the solution's architecture are:
4748
The above commands will also download the python libraries for the lambda layer.
4849
4950
## Deployment
50-
- Deploy the stack:
51+
- Deploy complete stack:
5152
5253
```
53-
cdk deploy --parameters opensearchAlertEmail='<your-alert-mailing-list@email.com>'
54-
```
54+
cdk deploy \
55+
--context opensearch-version='<OPENSEARCH_n_m>' \
56+
--parameters opensearchAlertEmail='<alert_email>'
57+
```
58+
This will do the following in the target account :
59+
1. Create CloudTrail trails with target CloudWatch log-group for the trails.
60+
2. Create OpenSearch Domain with Cognito auth for user management.
61+
3. Setup Cloudwatch subscription filter (using Lambda) to forward logs to OpenSearch.
62+
4. Create Lambda functions for Opensearch configuration automation(IAM Role mapping, anomaly detector creation).
63+
5. Create SNS topics for alerts and notification lambda for enriched notifications.
5564
56-
This will do the following in the target account :
57-
1. Create CloudTrail trails with target CloudWatch log-group for the trails.
58-
2. Create OpenSearch Domain with Cognito auth for user management.
59-
3. Setup Cloudwatch subscription filter (using Lambda) to forward logs to OpenSearch.
60-
4. Create Lambda functions for Opensearch configuration automation(IAM Role mapping, anomaly detector creation).
61-
5. Create SNS topics for alerts and notification lambda for enriched notifications.
65+
- Deploy to existing OpenSearch domain:
66+
67+
```
68+
cdk deploy \
69+
--context opensearch-version='<OPENSEARCH_n_m>' \
70+
--context opensearch-domain-endpoint='<endpoint_domain>' \
71+
--context opensearch-access-role-arn='<iam_role_arn>' \
72+
--parameters opensearchAlertEmail='<alert_email>'
73+
```
74+
This will create CloudTrail trail and ingest the trails to the provided OpenSearch domain. It will also create the anomaly detectors in the provided domain.
75+
For setting up the access IAM role, please check [existing_domain_deploy](./existing_domain_deploy.md) guide.
6276
6377
> NOTE: The IAM roles use AWS ManagedPolicies for various cases like lambdaExecution, etc. If required, please update to use self managed policies.
6478
6579
You can set the context to disable Lambda logging with the trail by setting: `--context enable-lambda-trail=false`. This will skip the Lambda Anomaly detector creation.
6680
67-
Furthermore, please examine the notification subscription confirmation email delivered to `<your-alert-mailing-list@email.com>` and confirm your subscription in order to obtain alert emails.
81+
Furthermore, please examine the notification subscription confirmation email delivered to `<alert_email>` and confirm your subscription in order to obtain alert emails.
6882
6983
## Usage
7084
Once the deployment process concludes, the output from the CDK stack offers essential links for utilizing the solution.
@@ -107,4 +121,4 @@ See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more inform
107121
108122
## License
109123
110-
This library is licensed under the MIT-0 License. See the LICENSE file.
124+
This library is licensed under the MIT-0 License. See the [LICENSE](LICENSE) file.

cdk.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
"aws-cn"
3939
],
4040
"stack-name": "usage-anomaly-detector-stack",
41-
"enable-lambda-trail": "true"
41+
"enable-lambda-trail": "true",
42+
"opensearch-version": "OPENSEARCH_2_9",
43+
"opensearch-domain-endpoint": "",
44+
"opensearch-access-role-arn": ""
4245
}
4346
}

existing_domain_deploy.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Usage Anomaly Detection Deployment on existing OpenSearch Domain
2+
3+
For deploying the solution to an existing OpenSearch domain, provide an IAM role with permissions to access the domain and basic AWS Lambda execution permissions.
4+
Please follow below steps for creating the role and setting permissions:
5+
1. Create role and add AWS Lambda execution permissions:
6+
```
7+
export USAGE_ANOMALY_DETECTION_IAM_ROLE_NAME="<role_name>"
8+
9+
aws iam create-role --role-name $USAGE_ANOMALY_DETECTION_IAM_ROLE_NAME --assume-role-policy-document '{"Version": "2012-10-17","Statement": [{ "Effect": "Allow", "Principal": {"Service": "lambda.amazonaws.com"}, "Action": "sts:AssumeRole"}]}'
10+
11+
aws iam attach-role-policy --role-name $USAGE_ANOMALY_DETECTION_IAM_ROLE_NAME --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
12+
```
13+
2. Map the IAM role arn in the OpenSearch all_access backend role, as shown in the screenshot below:
14+
![OpenSearch IAM role mapping](images/opensearch_iam_role_backend_mapping.png)
15+
16+
Once done, run the cdk deploy command given in the [readme](./README.md) file with the above IAM role arn and the target OpenSearch domain endpoint.
265 KB
Loading

0 commit comments

Comments
 (0)