Skip to content

Integration SNS Extension

Aryeh Citron edited this page Apr 22, 2026 · 8 revisions

Integration: Amazon SNS Extension

Track Amazon SNS operations in your test diagrams using the TestTrackingDiagrams.Extensions.SNS NuGet package. This extension intercepts SNS HTTP traffic via the AWS SDK's HttpClientFactory pipeline and logs operations for diagram generation.

Using a shared library or abstraction layer? If your code doesn't use the SNS SDK directly — e.g. it goes through MassTransit, a shared messaging library, or a custom abstraction — see the MassTransit Extension or Tracking Custom Dependencies for alternative approaches including MessageTracker and TrackingProxy<T>.

Installation

dotnet add package TestTrackingDiagrams.Extensions.SNS

Quick Start

using Amazon.SimpleNotificationService;
using TestTrackingDiagrams.Extensions.SNS;

var config = new AmazonSimpleNotificationServiceConfig
{
    RegionEndpoint = Amazon.RegionEndpoint.EUWest1
}
.WithTestTracking(new SnsTrackingMessageHandlerOptions
{
    ServiceName = "SNS",
    CallingServiceName = "OrdersApi",
    Verbosity = SnsTrackingVerbosity.Detailed,
    CurrentTestInfoFetcher = () => (TestContext.CurrentTestName, TestContext.CurrentTestId)
});

var client = new AmazonSimpleNotificationServiceClient(config);

How It Works

The extension uses the same DelegatingHandler pattern as the S3, DynamoDB, and SQS extensions. WithTestTracking() injects a SnsTrackingMessageHandler via AmazonSimpleNotificationServiceConfig.HttpClientFactory, intercepting all HTTP requests made by the SNS SDK.

The handler:

  1. Reads and classifies each request using SnsOperationClassifier
  2. Reconstructs the request body so downstream processing is unaffected
  3. Logs request/response pairs via RequestResponseLogger

Protocol Support

SNS supports two protocols:

Protocol Detection Example
JSON (modern) X-Amz-Target: AmazonSimpleNotificationService.{Operation} header AmazonSimpleNotificationService.Publish
Query (legacy) Action={Operation} parameter in query string or form body Action=Subscribe

Both protocols are fully supported by the classifier.

Supported Operations

Operation Enum Value
Publish SnsOperation.Publish
PublishBatch SnsOperation.PublishBatch
Subscribe SnsOperation.Subscribe
Unsubscribe SnsOperation.Unsubscribe
CreateTopic SnsOperation.CreateTopic
DeleteTopic SnsOperation.DeleteTopic
ListTopics SnsOperation.ListTopics
ListSubscriptions SnsOperation.ListSubscriptions
ListSubscriptionsByTopic SnsOperation.ListSubscriptionsByTopic
GetTopicAttributes SnsOperation.GetTopicAttributes
SetTopicAttributes SnsOperation.SetTopicAttributes
ConfirmSubscription SnsOperation.ConfirmSubscription

Unrecognised operations are classified as SnsOperation.Other.

Topic Name Extraction

The classifier extracts topic names from ARN fields in the request body:

  1. TopicArn field: "TopicArn": "arn:aws:sns:us-east-1:123456789012:my-topic"my-topic
  2. TargetArn field: "TargetArn": "arn:aws:sns:us-east-1:123456789012:endpoint-topic"endpoint-topic (used for direct publish to platform endpoints)

The topic name is extracted from the last segment of the ARN (after the final :). FIFO topic names (e.g. orders.fifo) are preserved with the .fifo suffix. The full ARN is also available via SnsOperationInfo.TopicArn.

Verbosity Levels

SnsTrackingVerbosity.Summarised

Minimal output for clean diagrams:

  • Method label: Operation name (e.g. Publish)
  • URI: sns:///my-topic
  • Content: Omitted (both request and response)
  • Headers: Omitted
  • Other operations: Skipped entirely

SnsTrackingVerbosity.Detailed

Balanced output for debugging:

  • Method label: Operation name (e.g. Publish)
  • URI: sns:///my-topic
  • Content: Included (request body and response body)
  • Headers: Included (with default exclusions)

SnsTrackingVerbosity.Raw

Full HTTP-level output:

  • Method: POST (actual HTTP method)
  • URI: Original AWS endpoint URL
  • Content: Full request/response bodies
  • Headers: All headers (with default exclusions)
  • Other operations: Included

Configuration Options

new SnsTrackingMessageHandlerOptions
{
    // Display name for this SNS instance in diagrams
    ServiceName = "SNS",

    // Name of the calling service in diagrams
    CallingServiceName = "OrdersApi",

    // Verbosity level (default: Detailed)
    Verbosity = SnsTrackingVerbosity.Detailed,

    // Required: provides test context for log correlation
    CurrentTestInfoFetcher = () => (testName, testId),

    // Headers excluded from logging (defaults below)
    ExcludedHeaders = new HashSet<string>
    {
        "Authorization", "x-amz-date", "x-amz-security-token",
        "x-amz-content-sha256", "User-Agent", "amz-sdk-invocation-id",
        "amz-sdk-request"
    }
}

ITrackingComponent

SnsTrackingMessageHandler implements ITrackingComponent and auto-registers with TrackingComponentRegistry on construction. This provides:

  • ComponentName: "SnsTrackingMessageHandler ({ServiceName})"
  • WasInvoked: true after first request
  • InvocationCount: Total requests processed

URI Scheme

Classified requests use the sns:/// URI scheme with the topic name in the path:

sns:///my-topic
sns:///orders.fifo
sns:///           (when topic name unavailable, e.g. ListTopics)

The path-based format (three slashes) preserves topic name casing, unlike host-based URIs which lowercase per RFC 3986.

SNS → SQS Fan-out

The most common SNS pattern is fan-out to SQS queues. When using both extensions together:

  • The SNS extension tracks the publish side (Publish → my-topic)
  • The SQS extension tracks the receive side (ReceiveMessage from my-queue)

Together they show the complete message flow in your test diagrams.

See Also

Home


Demo


Getting Started

Common Tasks

Integration Guides

Extensions

Configuration

Features

Reference

Clone this wiki locally