From aec999d78f2477ec01cf5705830a2e9b1d7d52db Mon Sep 17 00:00:00 2001 From: ParthaI Date: Wed, 10 Jan 2024 11:46:43 +0530 Subject: [PATCH 1/2] Update the table aws_sns_topic_subscription to use ListSubscriptionsByTopic API instead of ListSubscriptions --- aws/table_aws_sns_topic_subscription.go | 26 ++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/aws/table_aws_sns_topic_subscription.go b/aws/table_aws_sns_topic_subscription.go index e0daebb16..3699133a2 100644 --- a/aws/table_aws_sns_topic_subscription.go +++ b/aws/table_aws_sns_topic_subscription.go @@ -30,8 +30,12 @@ func tableAwsSnsTopicSubscription(_ context.Context) *plugin.Table { Tags: map[string]string{"service": "sns", "action": "GetSubscriptionAttributes"}, }, List: &plugin.ListConfig{ - Hydrate: listAwsSnsTopicSubscriptions, - Tags: map[string]string{"service": "sns", "action": "ListSubscriptions"}, + ParentHydrate: listAwsSnsTopics, + Hydrate: listAwsSnsTopicSubscriptions, + KeyColumns: plugin.KeyColumnSlice{ + {Name: "topic_arn", Require: plugin.Optional}, + }, + Tags: map[string]string{"service": "sns", "action": "ListSubscriptionsByTopic"}, }, HydrateConfig: []plugin.HydrateConfig{ { @@ -141,7 +145,17 @@ func tableAwsSnsTopicSubscription(_ context.Context) *plugin.Table { //// LIST FUNCTION -func listAwsSnsTopicSubscriptions(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { +func listAwsSnsTopicSubscriptions(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + if h.Item == nil { + return nil, nil + } + topic := h.Item.(*sns.GetTopicAttributesOutput) + topicArn := topic.Attributes["TopicArn"] + + if d.EqualsQualString("topic_arn") != "" && d.EqualsQualString("topic_arn") != topicArn { + return nil, nil + } + // Get Client svc, err := SNSClient(ctx, d) if err != nil { @@ -149,9 +163,11 @@ func listAwsSnsTopicSubscriptions(ctx context.Context, d *plugin.QueryData, _ *p return nil, err } - params := &sns.ListSubscriptionsInput{} + params := &sns.ListSubscriptionsByTopicInput{ + TopicArn: &topicArn, + } // Does not support limit - paginator := sns.NewListSubscriptionsPaginator(svc, params, func(o *sns.ListSubscriptionsPaginatorOptions) { + paginator := sns.NewListSubscriptionsByTopicPaginator(svc, params, func(o *sns.ListSubscriptionsByTopicPaginatorOptions) { o.StopOnDuplicateToken = true }) From b9eac5b54994cbaa641350b4ea3a79b93b5cda42 Mon Sep 17 00:00:00 2001 From: ParthaI Date: Thu, 11 Jan 2024 19:16:03 +0530 Subject: [PATCH 2/2] Updated the doc --- docs/tables/aws_sns_topic_subscription.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/tables/aws_sns_topic_subscription.md b/docs/tables/aws_sns_topic_subscription.md index 9b4c2b1f4..b57f62620 100644 --- a/docs/tables/aws_sns_topic_subscription.md +++ b/docs/tables/aws_sns_topic_subscription.md @@ -36,7 +36,6 @@ where redrive_policy is null; ``` - ### List of subscriptions which are not configured to filter messages Determine the areas in which subscriptions are not set up to filter messages. This is beneficial for identifying potential inefficiencies or areas of improvement within your notification system. @@ -60,7 +59,6 @@ where filter_policy is null; ``` - ### Subscription count by topic arn Determine the areas in which your AWS SNS topics are gaining the most traction by analyzing the number of subscriptions each topic has. This can help prioritize content creation and resource allocation for popular topics.