Skip to content

Commit

Permalink
check if nextToken exists in response
Browse files Browse the repository at this point in the history
handle nextToken missing key. nextToken is not returned when the number
of log groups is lower then the limit we set (50)
  • Loading branch information
dasfmi committed Aug 8, 2024
1 parent a42c502 commit f847432
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Axiom CloudWatch Forwarder includes templates for the following CloudFormation s
1. Create an Axiom organization at [app.axiom.co](https://app.axiom.co?ref=axiom-cloudwatch-forwarder).
2. Create a dataset in Axiom.
3. Create an API token in Axiom with permissions to ingest data to the dataset you created.
4. [Click this link](https://console.aws.amazon.com/cloudformation/home?#/stacks/new?stackName=axiom-cloudwatch-forwarder&templateURL=https://axiom-cloudformation.s3.amazonaws.com/stacks/axiom-cloudwatch-forwarder-v1.1.0-cloudformation-stack.yaml) to open the _Forwarder_ stack template.
4. [Click this link](https://console.aws.amazon.com/cloudformation/home?#/stacks/new?stackName=axiom-cloudwatch-forwarder&templateURL=https://axiom-cloudformation.s3.amazonaws.com/stacks/axiom-cloudwatch-forwarder-v1.1.1-cloudformation-stack.yaml) to open the _Forwarder_ stack template.
5. Copy the _Forwarder_ Lambda ARN from the previous step, as it will be referenced in the _Subscriber_ stack.
6. [Click this link](https://console.aws.amazon.com/cloudformation/home?#/stacks/new?stackName=axiom-cloudwatch-subscriber&templateURL=https://axiom-cloudformation.s3.amazonaws.com/stacks/axiom-cloudwatch-subscriber-v1.1.0-cloudformation-stack.yaml) to open the _Subscriber_ stack template.
7. [Click this link](https://console.aws.amazon.com/cloudformation/home?#/stacks/new?stackName=axiom-cloudwatch-listener&templateURL=https://axiom-cloudformation.s3.amazonaws.com/stacks/axiom-cloudwatch-listener-v1.1.0-cloudformation-stack.yaml) to open the _Listener_ stack template.
6. [Click this link](https://console.aws.amazon.com/cloudformation/home?#/stacks/new?stackName=axiom-cloudwatch-subscriber&templateURL=https://axiom-cloudformation.s3.amazonaws.com/stacks/axiom-cloudwatch-subscriber-v1.1.1-cloudformation-stack.yaml) to open the _Subscriber_ stack template.
7. [Click this link](https://console.aws.amazon.com/cloudformation/home?#/stacks/new?stackName=axiom-cloudwatch-listener&templateURL=https://axiom-cloudformation.s3.amazonaws.com/stacks/axiom-cloudwatch-listener-v1.1.1-cloudformation-stack.yaml) to open the _Listener_ stack template.

For guidance on unsubscribing from log groups, please see [Removing subscription filters](#Removing-subscription-filters) section below.

Expand Down Expand Up @@ -60,6 +60,6 @@ The optional _Listener_ stack does the following:

If later on you want to remove subscription filters for one or more log groups:

- [Click this link](https://console.aws.amazon.com/cloudformation/home?#/stacks/new?stackName=axiom-cloudwatch-subscriber&templateURL=https://axiom-cloudformation.s3.amazonaws.com/stacks/axiom-cloudwatch-unsubscriber-v1.1.0-cloudformation-stack.yaml) to open the _Unsubscriber_ stack template.
- [Click this link](https://console.aws.amazon.com/cloudformation/home?#/stacks/new?stackName=axiom-cloudwatch-subscriber&templateURL=https://axiom-cloudformation.s3.amazonaws.com/stacks/axiom-cloudwatch-unsubscriber-v1.1.1-cloudformation-stack.yaml) to open the _Unsubscriber_ stack template.

The log group filtering works the same way as the _Subscriber_ stack. You can filter the log groups by a combination of names, prefix and regular expression.
2 changes: 1 addition & 1 deletion subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_log_groups(nextToken=None):
# 2. AWS API https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeLogGroups.html#API_DescribeLogGroups_RequestSyntax
resp = cloudwatch_logs_client.describe_log_groups(limit=log_groups_return_limit)
all_groups = resp["logGroups"]
nextToken = resp["nextToken"]
nextToken = resp["nextToken"] if "nextToken" in resp else None
# continue fetching log groups until nextToken is None
while nextToken is not None:
resp = cloudwatch_logs_client.describe_log_groups(
Expand Down
2 changes: 1 addition & 1 deletion unsubscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_log_groups(nextToken=None):
# 2. AWS API https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeLogGroups.html#API_DescribeLogGroups_RequestSyntax
resp = cloudwatch_logs_client.describe_log_groups(limit=log_groups_return_limit)
all_groups = resp["logGroups"]
nextToken = resp["nextToken"]
nextToken = resp["nextToken"] if "nextToken" in resp else None
# continue fetching log groups until nextToken is None
while nextToken is not None:
resp = cloudwatch_logs_client.describe_log_groups(
Expand Down

0 comments on commit f847432

Please sign in to comment.