Amazon SNS message attributes - Amazon Simple Notification Service (original) (raw)

Amazon SNS supports delivery of message attributes, which let you provide structured metadata items (such as timestamps, geospatial data, signatures, and identifiers) about the message. For SQS subscriptions, a maximum of 10 message attributes can be sent when Raw Message Delivery is enabled. To send more than 10 message attributes, Raw Message Delivery must be disabled. Messages with more than 10 message attributes directed towards Raw Message Delivery enabled Amazon SQS subscriptions will be discarded as client side errors.

Message attributes are optional and separate from—but are sent together with—the message body. The receiver can use this information to decide how to handle the message without having to process the message body first.

For information about sending messages with attributes using the AWS Management Console or the AWS SDK for Java, see the To publish messages to Amazon SNS topics using the AWS Management Console tutorial.

Note

Message attributes are sent only when the message structure is String, not JSON.

You can also use message attributes to help structure the push notification message for mobile endpoints. In this scenario, the message attributes are used only to help structure the push notification message. The attributes are not delivered to the endpoint as they are when sending messages with message attributes to Amazon SQS endpoints.

You can also use message attributes to make your messages filterable using subscription filter policies. You can apply filter policies to topic subscriptions. When a filter policy is applied with filter policy scope set to MessageAttributes (default), a subscription receives only those messages that have attributes that the policy accepts. For more information, see Amazon SNS message filtering.

Note

When message attributes are used for filtering, the value must be a valid JSON string. Doing this ensures that the message is delivered to a subscription with message attributes filtering enabled.

Message attribute items and validation

Each message attribute consists of the following items:

Name, type, and value must not be empty or null. In addition, the message body should not be empty or null. All parts of the message attribute, including name, type, and value, are included in the message size restriction, which is 256 KB.

Message attribute data types and validation

Message attribute data types identify how the message attribute values are handled by Amazon SNS. For example, if the type is a number, Amazon SNS validates that it's a number.

Amazon SNS supports the following logical data types for all endpoints except as noted:

Note

Surrogate values are not supported in the message attributes. For example, using a surrogate value to represent an emoji will give you the following error: Invalid attribute value was passed in for message attribute.

Reserved message attributes for mobile push notifications

The following table lists the reserved message attributes for mobile push notification services that you can use to structure your push notification message:

Push notification service Reserved message attribute
ADM AWS.SNS.MOBILE.ADM.TTL
APNs1 AWS.SNS.MOBILE.APNS_MDM.TTL
AWS.SNS.MOBILE.APNS_MDM_SANDBOX.TTL
AWS.SNS.MOBILE.APNS_PASSBOOK.TTL
AWS.SNS.MOBILE.APNS_PASSBOOK_SANDBOX.TTL
AWS.SNS.MOBILE.APNS_SANDBOX.TTL
AWS.SNS.MOBILE.APNS_VOIP.TTL
AWS.SNS.MOBILE.APNS_VOIP_SANDBOX.TTL
AWS.SNS.MOBILE.APNS.COLLAPSE_ID
AWS.SNS.MOBILE.APNS.PRIORITY
AWS.SNS.MOBILE.APNS.PUSH_TYPE
AWS.SNS.MOBILE.APNS.TOPIC
AWS.SNS.MOBILE.APNS.TTL
Baidu AWS.SNS.MOBILE.BAIDU.DeployStatus
AWS.SNS.MOBILE.BAIDU.MessageKey
AWS.SNS.MOBILE.BAIDU.MessageType
AWS.SNS.MOBILE.BAIDU.TTL
FCM AWS.SNS.MOBILE.FCM.TTL
AWS.SNS.MOBILE.GCM.TTL
macOS AWS.SNS.MOBILE.MACOS_SANDBOX.TTL
AWS.SNS.MOBILE.MACOS.TTL
MPNS AWS.SNS.MOBILE.MPNS.NotificationClass
AWS.SNS.MOBILE.MPNS.TTL
AWS.SNS.MOBILE.MPNS.Type
WNS AWS.SNS.MOBILE.WNS.CachePolicy
AWS.SNS.MOBILE.WNS.Group
AWS.SNS.MOBILE.WNS.Match
AWS.SNS.MOBILE.WNS.SuppressPopup
AWS.SNS.MOBILE.WNS.Tag
AWS.SNS.MOBILE.WNS.TTL
AWS.SNS.MOBILE.WNS.Type

1 Apple will reject Amazon SNS notifications if message attributes do not meet their requirements. For additional details, see Sending Notification Requests to APNs on the Apple Developer website.