Skip to content

Commit

Permalink
retry adding permission in case that there was an issue with putting …
Browse files Browse the repository at this point in the history
…subscription to log group
  • Loading branch information
guyrenny committed Jul 1, 2024
1 parent 4887244 commit 865a29f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lambda-manager/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def lambda_handler(event, context):
status = add_subscription(filter_name, logs_filter, log_group_to_subscribe, destination_arn)
if status == cfnresponse.FAILED:
print(f"retrying to add subscription filter for {log_group_to_subscribe}")
add_permission_to_lambda(destination_arn, log_group_to_subscribe, region, account_id)
add_subscription(filter_name, logs_filter, log_group_to_subscribe, destination_arn)
except Exception as e:
print(f"Failed to put subscription filter for {log_group_to_subscribe}: {e}")
Expand Down Expand Up @@ -135,6 +136,7 @@ def list_log_groups_and_subscriptions(cloudwatch_logs, regex_pattern_list, logs_
status = add_subscription(filter_name, logs_filter, log_group_name, destination_arn)
if status == cfnresponse.FAILED:
print(f"retrying to add subscription filter for {log_group_name}")
add_permission_to_lambda(destination_arn, log_group_name, region, account_id)
add_subscription(filter_name, logs_filter, log_group_name, destination_arn)
else:
print(f"Adding subscription filter for {log_group_name}")
Expand Down Expand Up @@ -162,6 +164,7 @@ def add_subscription(filter_name: str, logs_filter: str, log_group_to_subscribe:
filterPattern=logs_filter,
logGroupName=log_group_to_subscribe,
)
print("Successfully put subscription filter for", log_group_to_subscribe)
return cfnresponse.SUCCESS
except Exception as e:
print(f"Failed to put subscription filter for {log_group_to_subscribe}: {e}")
Expand Down

0 comments on commit 865a29f

Please sign in to comment.