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 }) 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.