Interface SnsMessageManager

All Superinterfaces:
AutoCloseable, SdkAutoCloseable
All Known Implementing Classes:
DefaultSnsMessageManager

@SdkPublicApi public interface SnsMessageManager extends SdkAutoCloseable
Message manager for validating SNS message signatures. Create an instance using builder().

This manager provides automatic validation of SNS message signatures received via HTTP/HTTPS endpoints, ensuring that messages originate from Amazon SNS and have not been modified during transmission. It supports both SignatureVersion1 (SHA1) and SignatureVersion2 (SHA256) as per AWS SNS standards.

The manager handles certificate retrieval, caching, and validation automatically, supporting different AWS regions and partitions (aws, aws-gov, aws-cn).

Basic usage with default configuration:

 
 SnsMessageManager messageManager = SnsMessageManager.builder().build();

 try {
     SnsMessage validatedMessage = messageManager.parseMessage(messageBody);
     String messageContent = validatedMessage.message();
     String topicArn = validatedMessage.topicArn();
     // Process the validated message
 } catch (SdkClientException e) {
     // Handle validation failure
     logger.error("SNS message validation failed: {}", e.getMessage());
 }
 
 

Advanced usage with custom HTTP client:

 
 SnsMessageManager messageManager = SnsMessageManager.builder()
     .httpClient(ApacheHttpClient.create())
     .build();
 
 
See Also:
  • Method Details

    • builder

      static SnsMessageManager.Builder builder()
      Creates a builder for configuring and creating an SnsMessageManager.
      Returns:
      A new builder.
    • parseMessage

      SnsMessage parseMessage(InputStream messageStream)
      Parses and validates an SNS message from a stream.

      This method reads the JSON message payload, validates the signature, returns a parsed SNS message object with all message attributes if validation succeeds.

      Parameters:
      messageStream - The binary stream representation of the SNS message.
      Returns:
      The parsed SNS message.
    • parseMessage

      SnsMessage parseMessage(String messageContent)
      Parses and validates an SNS message from a string.

      This method reads the JSON message payload, validates the signature, returns a parsed SNS message object with all message attributes if validation succeeds.

      Parameters:
      messageContent - The string representation of the SNS message.
      Returns:
      the parsed SNS message.
    • close

      void close()
      Close this SnsMessageManager, releasing any resources it owned.

      Note: if you provided your own SdkHttpClient, you must close it separately.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface SdkAutoCloseable