Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the table aws_sns_topic_subscription to use ListSubscriptionsByTopic API instead of ListSubscriptions #2048

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions aws/table_aws_sns_topic_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down Expand Up @@ -141,17 +145,29 @@ 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 {
plugin.Logger(ctx).Error("aws_sns_topic_subscription.listAwsSnsTopicSubscriptions", "get_client_error", err)
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
})

Expand Down
2 changes: 0 additions & 2 deletions docs/tables/aws_sns_topic_subscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand Down