Skip to content

SNS Subscription attributes that might change between version of the app causes startup failure #646

@barp

Description

@barp

Steps to reproduce

Create an sns.NewSubscriber and override GenerateSubscribeInput to generate subscription attributes.
Successfully run the program once.

next change the attributes of the subscription and try to run again, creation will fail since the attributes have changed.

docker-compose.yml

	return sns.NewSubscriber(
		sns.SubscriberConfig{
			AWSConfig: *p.awsConfig,
			TopicResolver: &sns.TransparentTopicResolver{},
			GenerateSubscribeInput: func(ctx context.Context, params sns.GenerateSubscribeInputParams) (*awssns.SubscribeInput, error) {
				defaultParams, err := sns.GenerateSubscribeInputDefault(ctx, params)
				if err != nil {
					return nil, err
				}

				var policy *filterPolicy
				if optionValues.supportedEventTypes != nil {
					policy = &filterPolicy{Name: slices.Sorted(slices.Values(optionValues.supportedEventTypes))}
					policyData, err := json.Marshal(policy)
					if err != nil {
						return nil, err
					}
					defaultParams.Attributes["FilterPolicy"] = string(policyData)
					p.Logger().Info("queue attributes", "attributes", defaultParams.Attributes)
				}

				// Update subscription's filter policy - SNS Subscribe is idempotent but doesn't update attributes
				if err := p.updateSubscriptionFilterPolicy(ctx, string(params.SnsTopicArn), string(params.SqsQueueArn), policy); err != nil {
					p.Logger().Warn("Failed to update subscription filter policy", "error", err)
					// Continue anyway - the subscription will be created/reused
				}

				return defaultParams, nil
			},
		},
		sqs.SubscriberConfig{
			AWSConfig:   *p.awsConfig,
			Unmarshaler: &DefaultMarshalerUnmarshaler{},
			},
		},
		watermill.NewSlogLogger(p.Logger()),
	)

Expected behavior

The attributes of the subscription should change or a new subscription should be created and the old one deleted.

Actual behavior

cannot subscribe topic : cannot subscribe to SNS[] from : operation error SNS: Subscribe, https response error StatusCode: 400, RequestID: InvalidParameter: Invalid parameter: Attributes Reason: Subscription already exists with different attributes

Possible solution

The attributes of the subscription should change or a new subscription should be created and the old one deleted.

Is this intended behaviour of a bug?
I can submit a PR for this but I wanted to know what is the opinion on the suggested solution and whether this is intentional or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions