@@ -533,13 +533,20 @@ def publish(
533
533
if len (message ) > MAXIMUM_MESSAGE_LENGTH :
534
534
raise InvalidParameterException ("Invalid parameter: Message too long" )
535
535
536
- if topic_arn and ".fifo" in topic_arn :
536
+ # for compatibility reasons, AWS allows users to use either TargetArn or TopicArn for publishing to a topic
537
+ # use any of them for topic validation
538
+ topic_or_target_arn = topic_arn or target_arn
539
+
540
+ if topic_or_target_arn and ".fifo" in topic_or_target_arn :
537
541
if not message_group_id :
538
542
raise InvalidParameterException (
539
543
"Invalid parameter: The MessageGroupId parameter is required for FIFO topics" ,
540
544
)
541
545
moto_sns_backend = sns_backends [context .account_id ][context .region ]
542
- if moto_sns_backend .get_topic (arn = topic_arn ).content_based_deduplication == "false" :
546
+ if (
547
+ moto_sns_backend .get_topic (arn = topic_or_target_arn ).content_based_deduplication
548
+ == "false"
549
+ ):
543
550
if not message_deduplication_id :
544
551
raise InvalidParameterException (
545
552
"Invalid parameter: The topic should either have ContentBasedDeduplication enabled or MessageDeduplicationId provided explicitly" ,
@@ -581,8 +588,7 @@ def publish(
581
588
"Invalid parameter: TargetArn Reason: No endpoint found for the target arn specified"
582
589
)
583
590
else :
584
- topic = topic_arn or target_arn
585
- if topic not in store .sns_subscriptions :
591
+ if topic_or_target_arn not in store .sns_subscriptions :
586
592
raise NotFoundException (
587
593
"Topic does not exist" ,
588
594
)
@@ -610,7 +616,7 @@ def publish(
610
616
# beware if the subscription is FIFO, the order might not be guaranteed.
611
617
# 2 quick call to this method in succession might not be executed in order in the executor?
612
618
# TODO: test how this behaves in a FIFO context with a lot of threads.
613
- self ._publisher .publish_to_topic (publish_ctx , topic_arn or target_arn )
619
+ self ._publisher .publish_to_topic (publish_ctx , topic_or_target_arn )
614
620
615
621
return PublishResponse (MessageId = message_ctx .message_id )
616
622
0 commit comments