Skip to content

Commit

Permalink
🐛 fix cloudwatch metrics alarms when sns topic does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeffrey committed Feb 5, 2024
1 parent cf84191 commit 36575a3
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion providers/aws/resources/aws_sns.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ func (a *mqlAwsSnsTopic) attributes() (interface{}, error) {

topicAttributes, err := svc.GetTopicAttributes(ctx, &sns.GetTopicAttributesInput{TopicArn: &arn})
if err != nil {
var respErr *http.ResponseError
if errors.As(err, &respErr) {
if respErr.HTTPStatusCode() == 404 {
// setting the err here returns an err for the query
a.Attributes = plugin.TValue[interface{}]{State: plugin.StateIsSet | plugin.StateIsNull}
return nil, nil
}
}
return nil, err
}
return convert.JsonToDict(topicAttributes.Attributes)
Expand Down Expand Up @@ -170,13 +178,20 @@ func (a *mqlAwsSnsTopic) subscriptions() ([]interface{}, error) {

svc := conn.Sns(regionVal)
ctx := context.Background()

mqlSubs := []interface{}{}
params := &sns.ListSubscriptionsByTopicInput{TopicArn: &arnValue}
nextToken := aws.String("no_token_to_start_with")
for nextToken != nil {
subsByTopic, err := svc.ListSubscriptionsByTopic(ctx, params)
if err != nil {
var respErr *http.ResponseError
if errors.As(err, &respErr) {
if respErr.HTTPStatusCode() == 404 {
// setting the err here returns an err for the query
a.Subscriptions = plugin.TValue[[]interface{}]{State: plugin.StateIsSet | plugin.StateIsNull}
return nil, nil
}
}
return nil, err
}
nextToken = subsByTopic.NextToken
Expand Down

0 comments on commit 36575a3

Please sign in to comment.