Skip to content

Commit

Permalink
Fix subscription filters (#1172)
Browse files Browse the repository at this point in the history
* Adding fix to only remove subscription filters if they are created by ASEA

* Fixing prettier

* Fixing prettier

* Prettier, again

* Adding last line

---------

Co-authored-by: Ryan Cerrato <rycerrat@amazon.com>
  • Loading branch information
archikierstead and rycerrat committed Jul 17, 2023
1 parent e7b5c54 commit 08c00da
Showing 1 changed file with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,14 @@ async function centralLoggingSubscription(event: CloudFormationCustomResourceEve
await Promise.all(
filterLogGroups.map(async logGroup => {
// Get Subscription filter and remove
const filterName = `${CloudWatchRulePrefix}${logGroup.logGroupName}`;
const subscriptinFilters = await getSubscriptionFilters(logGroup.logGroupName!);
if (subscriptinFilters && subscriptinFilters.length > 0) {
// Remove existing Subscription filters
for (const subscriptinFilter of subscriptinFilters) {
await removeSubscriptionFilter(logGroup.logGroupName!, subscriptinFilter.filterName!);
if (subscriptinFilter.filterName === filterName) {
await removeSubscriptionFilter(logGroup.logGroupName!, subscriptinFilter.filterName);
}
}
}
// Change Log Retention for Log Group
Expand All @@ -125,22 +128,16 @@ async function centralLoggingSubscriptionUpdate(event: CloudFormationCustomResou
const logGroups = await getLogGroups();
const filterLogGroups = logGroups.filter(lg => !isExcluded(globalExclusions, lg.logGroupName!));

await Promise.all(
logGroups.map(async logGroup => {
// Remove "PBMM-" Subscription filter from all log Groups if exists on update
const filterName = `${CloudWatchRulePrefix}${logGroup.logGroupName}`;
await removeSubscriptionFilter(logGroup.logGroupName!, filterName);
}),
);

await Promise.all(
filterLogGroups.map(async logGroup => {
// Get Subscription filter and remove
const subscriptinFilters = await getSubscriptionFilters(logGroup.logGroupName!);
const filterName = `${CloudWatchRulePrefix}${logGroup.logGroupName}`;
if (subscriptinFilters && subscriptinFilters.length > 0) {
// Remove existing Subscription filters
for (const subscriptinFilter of subscriptinFilters) {
await removeSubscriptionFilter(logGroup.logGroupName!, subscriptinFilter.filterName!);
if (subscriptinFilter.filterName === filterName) {
await removeSubscriptionFilter(logGroup.logGroupName!, subscriptinFilter.filterName);
}
}
}
// Change Log Retention for Log Group
Expand Down

0 comments on commit 08c00da

Please sign in to comment.