Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding CLI examples for CloudWatch Logs #9303

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions awscli/examples/logs/delete-index-policy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**To delete a log-group level field index policy**

The following ``delete-index-policy`` example deletes a log-group level field index policy that was applied to a single log group. ::

aws logs delete-index-policy \
--log-group-identifier arn:aws:logs:us-east-1:123456789012:log-group:CWLG

This command produces no output.

For more information, see `Amazon CloudWatch Logs <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html>`__ in the *Amazon CloudWatch User Guide*.
10 changes: 10 additions & 0 deletions awscli/examples/logs/delete-transformer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**To delete the log transformer**

The following ``delete-transformer`` example deletes the log transformer for the specified log group. ::

aws logs delete-transformer \
--log-group-identifier arn:aws:logs:us-east-1:123456789012:log-group:CWLG

This command produces no output.

For more information, see `Amazon CloudWatch Logs <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html>`__ in the *Amazon CloudWatch User Guide*.
21 changes: 21 additions & 0 deletions awscli/examples/logs/describe-field-indexes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
**To return a list of field indexes**

The following ``describe-field-indexes`` example returns a list of field indexes listed in the field index policies of one or more log groups. ::

aws logs describe-field-indexes \
--log-group-identifiers arn:aws:logs:us-east-1:123456789012:log-group:CWLG

Output::

{
"fieldIndexes": [
{
"logGroupIdentifier": "arn:aws:logs:us-east-1:123456789012:log-group:CWLG",
"fieldIndexName": "@logStream",
"firstEventTime": 1738039122783,
"lastEventTime": 1738039239900
}
]
}

For more information, see `Amazon CloudWatch Logs <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html>`__ in the *Amazon CloudWatch User Guide*.
21 changes: 21 additions & 0 deletions awscli/examples/logs/describe-index-policies.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
**To return returns the field index policies**

The following ``describe-index-policies`` example returns the field index policies of one or more log groups. ::

aws logs describe-index-policies \
--log-group-identifiers arn:aws:logs:us-east-1:123456789012:log-group:CWLG

Output::

{
"indexPolicies": [
{
"logGroupIdentifier": "arn:aws:logs:us-east-1:123456789012:log-group:CWLG",
"lastUpdateTime": 1738040112829,
"policyDocument": "{\"Fields\":[\"@ingestionTime\",\"@requestId\"]}",
"source": "LOG_GROUP"
}
]
}

For more information, see `Amazon CloudWatch Logs <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html>`__ in the *Amazon CloudWatch User Guide*.
44 changes: 44 additions & 0 deletions awscli/examples/logs/get-transformer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
**To return the information about the log transformer**

The following ``get-transformer`` example returns the information about the log transformer associated with this log group. ::

aws logs get-transformer \
--log-group-identifier arn:aws:logs:us-east-1:123456789012:log-group:CWLG

Output::

{
"logGroupIdentifier": "CWLG",
"creationTime": 1734944243820,
"lastModifiedTime": 1738037681546,
"transformerConfig": [
{
"parseJSON": {}
},
{
"addKeys": {
"entries": [
{
"key": "metadata.transformed_in",
"value": "CloudWatchLogs",
"overwriteIfExists": false
},
{
"key": "feature",
"value": "Transformation",
"overwriteIfExists": false
}
]
}
},
{
"trimString": {
"withKeys": [
"status"
]
}
}
]
}

For more information, see `Amazon CloudWatch Logs <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html>`__ in the *Amazon CloudWatch User Guide*.
20 changes: 20 additions & 0 deletions awscli/examples/logs/put-index-policy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
**To create or update a field index policy**

The following ``put-index-policy`` example creates or updates a field index policy for the specified log group. ::

aws logs put-index-policy \
--log-group-identifier arn:aws:logs:us-east-1:123456789012:log-group:CWLG \
--policy-document "{\"Fields\":[\"@ingestionTime\",\"@requestId\"]}"

Output::

{
"indexPolicy": {
"logGroupIdentifier": "arn:aws:logs:us-east-1:123456789012:log-group:CWLG",
"lastUpdateTime": 1738040112829,
"policyDocument": "{\"Fields\":[\"@ingestionTime\",\"@requestId\"]}",
"source": "LOG_GROUP"
}
}

For more information, see `Amazon CloudWatch Logs <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html>`__ in the *Amazon CloudWatch User Guide*.
11 changes: 11 additions & 0 deletions awscli/examples/logs/put-transformer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
**To create or update a log transformer**

The following ``put-transformer`` example creates or updates a log transformer for a single log group. ::

aws logs put-transformer \
--transformer-config '[{"parseJSON":{}},{"addKeys":{"entries":[{"key":"metadata.transformed_in","value":"CloudWatchLogs"},{"key":"feature","value":"Transformation"}]}},{"trimString":{"withKeys":["status"]}}]' \
--log-group-identifier arn:aws:logs:us-east-1:123456789012:log-group:CWLG

This command produces no output.

For more information, see `Amazon CloudWatch Logs <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html>`__ in the *Amazon CloudWatch User Guide*.
21 changes: 21 additions & 0 deletions awscli/examples/logs/test-transformer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
**To test a log transformer**

The following ``test-transformer`` example is used to test a log transformer. ::

aws logs test-transformer \
--transformer-config "[{\"grok\":{\"source\":\"@message\",\"match\":\"%{NUMBER:version} %{HOSTNAME:hostname} %{NOTSPACE:status} %{QUOTEDSTRING:logMsg}\"}},{\"addKeys\":{\"entries\":[{\"key\":\"environment\",\"value\":\"Prd-Application-01\",\"overwriteIfExists\":false}]}}]"
--log-event-messages "293750 server-01.internal-network.local OK \"[Thread-000] token generated\""

Output::

{
"transformedLogs": [
{
"eventNumber": 1,
"eventMessage": "293750 server-01.internal-network.local OK \"[Thread-000] token generated\"",
"transformedEventMessage": "{\"version\":\"293750\",\"hostname\":\"server-01.internal-network.local\",\"status\":\"OK\",\"logMsg\":\"[Thread-000] token generated\",\"environment\":\"Prd-Application-01\"}"
}
]
}

For more information, see `Amazon CloudWatch Logs <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html>`__ in the *Amazon CloudWatch User Guide*.