Skip to content

Commit a4a4dca

Browse files
committed
Adding CLI examples for CloudWatch Logs
1 parent e29b00a commit a4a4dca

8 files changed

+165
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
**To delete a log-group level field index policy**
2+
3+
The following ``delete-index-policy`` example deletes a log-group level field index policy that was applied to a single log group. ::
4+
5+
aws logs delete-index-policy \
6+
--log-group-identifier arn:aws:logs:us-east-1:123456789012:log-group:CWLG
7+
8+
Output::
9+
none
10+
11+
For more information, see `Amazon CloudWatch Logs <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html>`__ in the *Amazon CloudWatch User Guide*.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
**To delete the log transformer**
2+
3+
The following ``delete-transformer`` example deletes the log transformer for the specified log group. ::
4+
5+
6+
aws logs delete-transformer \
7+
--log-group-identifier arn:aws:logs:us-east-1:123456789012:log-group:CWLG
8+
9+
Output::
10+
none
11+
12+
For more information, see `Amazon CloudWatch Logs <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html>`__ in the *Amazon CloudWatch User Guide*.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
**To return a list of field indexes**
2+
3+
The following ``describe-field-indexes`` example returns a list of field indexes listed in the field index policies of one or more log groups. ::
4+
5+
6+
aws logs describe-field-indexes \
7+
--log-group-identifiers arn:aws:logs:us-east-1:123456789012:log-group:CWLG
8+
9+
Output::
10+
{
11+
"fieldIndexes": [
12+
{
13+
"logGroupIdentifier": "arn:aws:logs:us-east-1:123456789012:log-group:CWLG",
14+
"fieldIndexName": "@logStream",
15+
"firstEventTime": 1738039122783,
16+
"lastEventTime": 1738039239900
17+
}
18+
]
19+
}
20+
21+
For more information, see `Amazon CloudWatch Logs <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html>`__ in the *Amazon CloudWatch User Guide*.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
**To return returns the field index policies**
2+
3+
The following ``describe-index-policies`` example returns the field index policies of one or more log groups. ::
4+
5+
6+
aws logs describe-index-policies \
7+
--log-group-identifiers arn:aws:logs:us-east-1:123456789012:log-group:CWLG
8+
9+
Output::
10+
11+
{
12+
"indexPolicies": [
13+
{
14+
"logGroupIdentifier": "arn:aws:logs:us-east-1:123456789012:log-group:CWLG",
15+
"lastUpdateTime": 1738040112829,
16+
"policyDocument": "{\"Fields\":[\"@ingestionTime\",\"@requestId\"]}",
17+
"source": "LOG_GROUP"
18+
}
19+
]
20+
}
21+
22+
For more information, see `Amazon CloudWatch Logs <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html>`__ in the *Amazon CloudWatch User Guide*.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
**To return the information about the log transformer**
2+
3+
The following ``get-transformer`` example returns the information about the log transformer associated with this log group. ::
4+
5+
6+
aws logs get-transformer \
7+
--log-group-identifier arn:aws:logs:us-east-1:123456789012:log-group:CWLG
8+
9+
Output::
10+
11+
{
12+
"logGroupIdentifier": "CWLG",
13+
"creationTime": 1734944243820,
14+
"lastModifiedTime": 1738037681546,
15+
"transformerConfig": [
16+
{
17+
"parseJSON": {}
18+
},
19+
{
20+
"addKeys": {
21+
"entries": [
22+
{
23+
"key": "metadata.transformed_in",
24+
"value": "CloudWatchLogs",
25+
"overwriteIfExists": false
26+
},
27+
{
28+
"key": "feature",
29+
"value": "Transformation",
30+
"overwriteIfExists": false
31+
}
32+
]
33+
}
34+
},
35+
{
36+
"trimString": {
37+
"withKeys": [
38+
"status"
39+
]
40+
}
41+
}
42+
]
43+
}
44+
45+
For more information, see `Amazon CloudWatch Logs <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html>`__ in the *Amazon CloudWatch User Guide*.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
**To create or update a field index policy**
2+
3+
The following ``put-index-policy`` example creates or updates a field index policy for the specified log group. ::
4+
5+
aws logs put-index-policy \
6+
--log-group-identifier arn:aws:logs:us-east-1:123456789012:log-group:CWLG \
7+
--policy-document "{\"Fields\":[\"@ingestionTime\",\"@requestId\"]}"
8+
9+
Output::
10+
{
11+
"indexPolicy": {
12+
"logGroupIdentifier": "arn:aws:logs:us-east-1:123456789012:log-group:CWLG",
13+
"lastUpdateTime": 1738040112829,
14+
"policyDocument": "{\"Fields\":[\"@ingestionTime\",\"@requestId\"]}",
15+
"source": "LOG_GROUP"
16+
}
17+
}
18+
19+
For more information, see `Amazon CloudWatch Logs <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html>`__ in the *Amazon CloudWatch User Guide*.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
**To create or update a log transformer**
2+
3+
The following ``put-transformer`` example creates or updates a log transformer for a single log group. ::
4+
5+
6+
aws logs put-transformer \
7+
--transformer-config '[{"parseJSON":{}},{"addKeys":{"entries":[{"key":"metadata.transformed_in","value":"CloudWatchLogs"},{"key":"feature","value":"Transformation"}]}},{"trimString":{"withKeys":["status"]}}]' \
8+
--log-group-identifier arn:aws:logs:us-east-1:123456789012:log-group:CWLG
9+
10+
Output::
11+
none
12+
13+
For more information, see `Amazon CloudWatch Logs <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html>`__ in the *Amazon CloudWatch User Guide*.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
**To test a log transformer**
2+
3+
The following ``test-transformer`` example is used to test a log transformer. ::
4+
5+
6+
aws logs test-transformer \
7+
--transformer-config "[{\"grok\":{\"source\":\"@message\",\"match\":\"%{NUMBER:version} %{HOSTNAME:hostname} %{NOTSPACE:status} %{QUOTEDSTRING:logMsg}\"}},{\"addKeys\":{\"entries\":[{\"key\":\"environment\",\"value\":\"Prd-Application-01\",\"overwriteIfExists\":false}]}}]"
8+
--log-event-messages "293750 server-01.internal-network.local OK \"[Thread-000] token generated\""
9+
10+
Output::
11+
12+
{
13+
"transformedLogs": [
14+
{
15+
"eventNumber": 1,
16+
"eventMessage": "293750 server-01.internal-network.local OK \"[Thread-000] token generated\"",
17+
"transformedEventMessage": "{\"version\":\"293750\",\"hostname\":\"server-01.internal-network.local\",\"status\":\"OK\",\"logMsg\":\"[Thread-000] token generated\",\"environment\":\"Prd-Application-01\"}"
18+
}
19+
]
20+
}
21+
22+
For more information, see `Amazon CloudWatch Logs <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html>`__ in the *Amazon CloudWatch User Guide*.

0 commit comments

Comments
 (0)