sns

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2020 License: Apache-2.0 Imports: 17 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SNS

type SNS struct {
	// define the AWS region that SNS is located at
	AwsRegion awsregion.AWSRegion

	// custom http2 client options
	HttpOptions *awshttp2.HttpClientSettings

	// optional, sms sender name info
	SMSSenderName string

	// optional, indicates if sms message sent is transaction or promotional
	SMSTransactional bool
	// contains filtered or unexported fields
}

SNS struct encapsulates the AWS SNS access functionality

func (*SNS) CheckIfPhoneNumberIsOptedOut

func (s *SNS) CheckIfPhoneNumberIsOptedOut(phoneNumber string, timeOutDuration ...time.Duration) (optedOut bool, err error)

CheckIfPhoneNumberIsOptedOut will verify if a phone number is opted out of message reception

Parameters:

  1. phoneNumber = required, phone number to check if opted out. Use E.164 format (+12095551212 where +1 is country code)
  2. timeOutDuration = optional, indicates timeout value for context

Return Values:

  1. optedOut = bool indicating if the given phone via input parameter was opted out (true), or not (false)
  2. err = error info if any

func (*SNS) ConfirmSubscription

func (s *SNS) ConfirmSubscription(topicArn string, token string, timeOutDuration ...time.Duration) (subscriptionArn string, err error)

ConfirmSubscription will confirm a pending subscription upon receive of SNS notification for subscription confirmation, the SNS subscription confirmation will contain a Token which is needed by ConfirmSubscription as input parameter in order to confirm,

Parameters:

  1. topicArn = required, the topic in SNS to confirm subscription for
  2. token = required, the token from SNS confirmation notification receive upon call to Subscribe
  3. timeOutDuration = optional, indicates timeout value for context

Return Values:

  1. subscriptionArn = upon confirmation, the subscription ARN attained
  2. err = the error info if any

Subscription Confirmation Support:

  1. Http / Https / Email Endpoints Requires Subscription Confirmation Support, See Details in URL Below: a) https://docs.aws.amazon.com/sns/latest/dg/sns-http-https-endpoint-as-subscriber.html
  2. Once Subscribe action is performed, SNS sends confirmation notification to the HTTP/s Endpoint: b) Client Upon Receipt of the SNS Notification, Retrieve Token and Respond via ConfirmSubscription method

func (*SNS) Connect

func (s *SNS) Connect() error

Connect will establish a connection to the SNS service

func (*SNS) CreatePlatformApplication

func (s *SNS) CreatePlatformApplication(name string,
	platform snsapplicationplatform.SNSApplicationPlatform,
	attributes map[snsplatformapplicationattribute.SNSPlatformApplicationAttribute]string,
	timeOutDuration ...time.Duration) (platformApplicationArn string, err error)

CreatePlatformApplication will create a SNS platform application used for app notification via APNS, FCM, ADM etc. this method creates the application so that then Endpoint (devices that receives) for this application may be created to complete the setup.

Once the application and endpoint is created, then for a device to Subscribe to a topic and receive SNS notifications via APNS, FCM, etc, the device will use the Subscribe's protocol as Application, and specify the Endpoint ARN accordingly.

For the device to receive SNS notifications when provider Publish, the appropriate protocol specific setup is needed during Endpoint creation, for example, APNS requires to set private key and SSL certificate in Application Attributes' PlatformCredential and PlatformPrincipal (See notes below)

In general, first create the Application via CreatePlatformApplication, Once application exists, then for each device that needs to receive SNS notification, create the appropriate Endpoint via CreatePlatformEndpoint

Parameters:

  1. name = required, platform application name
  2. platform = required, the sns platform association with this application, such as APNS, FCM etc.
  3. attributes = required, map of platform application attributes that defines specific values related to the chosen platform (see notes below)
  4. timeOutDuration = optional, indicates timeout value for context

Return Values:

  1. platformApplicationArn = the created platform application's ARN
  2. err = error info if any

Platform Application Attributes: (Key = Expected Value)

  1. PlatformCredential = The credential received from the notification service, For APNS and APNS_SANDBOX, PlatformCredential is the private key For GCM (Firebase Cloud Messaging), PlatformCredential is API key For ADM, PlatformCredential is client secret
  2. PlatformPrincipal = The principal received from the notification service, For APNS and APNS_SANDBOX, PlatformPrincipal is SSL certificate For GCM (Firebase Cloud Messaging), there is no PlatformPrincipal For ADM, PlatformPrincipal is client id
  3. EventEndpointCreated = Topic ARN to which EndpointCreated event notifications are sent
  4. EventEndpointDeleted = Topic ARN to which EndpointDeleted event notifications are sent
  5. EventEndpointUpdated = Topic ARN to which EndpointUpdate event notifications are sent
  6. EventDeliveryFailure = Topic ARN to which DeliveryFailure event notifications are sent upon Direct Publish delivery failure (permanent) to one of the application's endpoints
  7. SuccessFeedbackRoleArn = IAM role ARN used to give Amazon SNS write access to use CloudWatch Logs on your behalf
  8. FailureFeedbackRoleArn = IAM role ARN used to give Amazon SNS write access to use CloudWatch Logs on your behalf
  9. SuccessFeedbackSampleRate = Sample rate percentage (0-100) of successfully delivered messages

func (*SNS) CreatePlatformEndpoint

func (s *SNS) CreatePlatformEndpoint(platformApplicationArn string,
	token string,
	customUserData string,
	timeOutDuration ...time.Duration) (endpointArn string, err error)

CreatePlatformEndpoint will create a device endpoint for a specific platform application, this is the endpoint that will receive SNS notifications via defined protocol such as APNS or FCM

Parameters:

  1. platformApplicationArn = required, Plaform application ARN that was created, endpoint is added to this platform application
  2. token = Unique identifier created by the notification service for an app on a device, The specific name for Token will vary, depending on which notification service is being used, For example, when using APNS as the notification service, you need the device token, Alternatively, when using FCM or ADM, the device token equivalent is called the registration ID
  3. customUserData = optional, Arbitrary user data to associate with the endpoint, Amazon SNS does not use this data. The data must be in UTF-8 format and less than 2KB
  4. timeOutDuration = optional, indicates timeout value for context

Return Values:

  1. endpointArn = the created endpoint ARN
  2. err = the error info if any

func (*SNS) CreateTopic

func (s *SNS) CreateTopic(topicName string, attributes map[snscreatetopicattribute.SNSCreateTopicAttribute]string, timeOutDuration ...time.Duration) (topicArn string, err error)

CreateTopic will create a new topic in SNS for clients to subscribe, once topic is created, the topicArn is returned for subsequent uses

Parameters:

  1. topicName = required, the name of the topic to create in SNS
  2. attributes = optional, topic attributes to further customize the topic
  3. timeOutDuration = optional, indicates timeout value for context

Topic Attributes: (Key = Expected Value)

  1. DeliveryPolicy = The JSON serialization of the topic's delivery policy
  2. DisplayName = The human-readable name used in the From field for notifications to email and email-json endpoints
  3. Policy = The JSON serialization of the topic's access control policy

The following attribute applies only to server-side-encryption (https://docs.aws.amazon.com/sns/latest/dg/sns-server-side-encryption.html):

   	a) KmsMasterKeyId = The ID of an AWS-managed customer master key (CMK) for Amazon SNS or a custom CMK.
						For more information, see Key Terms (https://docs.aws.amazon.com/sns/latest/dg/sns-server-side-encryption.html#sse-key-terms)
   						For more examples, see KeyId (https://docs.aws.amazon.com/kms/latest/APIReference/API_DescribeKey.html#API_DescribeKey_RequestParameters) in the AWS Key Management Service API Reference

func (*SNS) DeletePlatformApplication

func (s *SNS) DeletePlatformApplication(platformApplicationArn string, timeOutDuration ...time.Duration) error

DeletePlatformApplication will delete a platform application by platformApplicationArn, returns nil if successful, otherwise error info is returned

Parameters:

  1. platformApplicationArn = the platform application to delete via platform application ARN specified
  2. timeOutDuration = optional, indicates timeout value for context

func (*SNS) DeletePlatformEndpoint

func (s *SNS) DeletePlatformEndpoint(endpointArn string, timeOutDuration ...time.Duration) error

DeletePlatformEndpoint will delete an endpoint based on endpointArn, returns nil if successful, otherwise error info is returned

Parameters:

  1. endpointArn = required, the endpoint to delete
  2. timeOutDuration = optional, indicates timeout value for context

func (*SNS) DeleteTopic

func (s *SNS) DeleteTopic(topicArn string, timeOutDuration ...time.Duration) error

DeleteTopic will delete an existing SNS topic by topicArn, returns nil if successful

func (*SNS) Disconnect

func (s *SNS) Disconnect()

Disconnect will disjoin from aws session by clearing it

func (*SNS) GetPlatformApplicationAttributes

func (s *SNS) GetPlatformApplicationAttributes(platformApplicationArn string, timeOutDuration ...time.Duration) (attributes map[snsplatformapplicationattribute.SNSPlatformApplicationAttribute]string, err error)

GetPlatformApplicationAttributes will retrieve application attributes based on a specific platform application ARN

Parameters:

  1. platformApplicationArn = required, the platform application ARN used to retrieve related application attributes
  2. timeOutDuration = optional, indicates timeout value for context

Return Values:

  1. attributes = map of sns platform application attributes related to the given platform application ARN
  2. err = error info if any

func (*SNS) GetPlatformEndpointAttributes

func (s *SNS) GetPlatformEndpointAttributes(endpointArn string, timeOutDuration ...time.Duration) (attributes map[snsendpointattribute.SNSEndpointAttribute]string, err error)

GetPlatformEndpointAttributes will retrieve endpoint attributes based on a specific endpoint ARN

Parameters:

  1. endpointArn = required, the endpoint ARN used to retrieve related endpoint attributes
  2. timeOutDuration = optional, indicates timeout value for context

Return Values:

  1. attributes = map of sns endpoint attributes related to the given endpoint ARN
  2. err = error info if any

Endpoint Attributes: (Key = Expected Value)

  1. CustomUserData = arbitrary user data to associate with the endpoint. Amazon SNS does not use this data. The data must be in UTF-8 format and less than 2KB.
  2. Enabled = flag that enables/disables delivery to the endpoint. Amazon SNS will set this to false when a notification service indicates to Amazon SNS that the endpoint is invalid. Users can set it back to true, typically after updating Token.
  3. Token = device token, also referred to as a registration id, for an app and mobile device. This is returned from the notification service when an app and mobile device are registered with the notification service. The device token for the iOS platform is returned in lowercase.

func (*SNS) GetSubscriptionAttributes

func (s *SNS) GetSubscriptionAttributes(subscriptionArn string, timeOutDuration ...time.Duration) (attributes map[snsgetsubscriptionattribute.SNSGetSubscriptionAttribute]string, err error)

GetSubscriptionAttributes will retrieve all subscription attributes for a specific subscription based on subscriptionArn

Parameters:

  1. subscriptionArn = required, the subscriptionArn for which attributes are retrieved from
  2. timeOutDuration = optional, indicates timeout value for context

Return Values:

  1. attributes = map of sns get subscription attributes in key value pairs
  2. err = error info if any

Subscription Attributes: (Key = Expected Value)

  1. ConfirmationWasAuthenticated = true if the subscription confirmation request was authenticated
  2. DeliveryPolicy = The JSON serialization of the subscription's delivery policy (See Subscribe Notes)
  3. EffectiveDeliveryPolicy = The JSON serialization of the effective delivery policy that takes into account the topic delivery policy, and account system defaults (See Subscribe Notes for DeliveryPolicy Json format)
  4. FilterPolicy = The filter policy JSON that is assigned to the subscription (See Subscribe Notes)
  5. Owner = The AWS account ID of the subscription's owner
  6. PendingConfirmation = true if the subscription hasn't been confirmed, To confirm a pending subscription, call the ConfirmSubscription action with a confirmation token
  7. RawMessageDelivery = true if raw message delivery is enabled for the subscription. Raw messages are free of JSON formatting and can be sent to HTTP/S and Amazon SQS endpoints
  8. RedrivePolicy = When specified, sends undeliverable messages to the specified Amazon SQS dead-letter queue. Messages that can't be delivered due to client errors (for example, when the subscribed endpoint is unreachable), or server errors (for example, when the service that powers the subscribed endpoint becomes unavailable) are held in the dead-letter queue for further analysis or reprocessing (See Subscribe Notes)
  9. SubscriptionArn = The subscription's ARN
  10. TopicArn = The topic ARN that the subscription is associated with

func (*SNS) GetTopicAttributes

func (s *SNS) GetTopicAttributes(topicArn string, timeOutDuration ...time.Duration) (attributes map[snsgettopicattribute.SNSGetTopicAttribute]string, err error)

GetTopicAttributes will retrieve a map of topic attributes based on topicArn

Parameters:

  1. topicArn = required, specify the topicArn to retrieve related topic attributes
  2. timeOutDuration = optional, indicates timeout value for context

Return Values:

  1. attributes = map of sns get topic attributes key value pairs related to teh topic ARN being queried
  2. err = error info if any

Topic Attributes: (Key = Expected Value)

  1. DeliveryPolicy = The JSON serialization of the topic's delivery policy (See Subscribe DeliveryPolicy Json Format)
  2. DisplayName = The human-readable name used in the From field for notifications to email and email-json endpoints
  3. Owner = The AWS account ID of the topic's owner
  4. Policy = The JSON serialization of the topic's access control policy
  5. SubscriptionsConfirmed = The number of confirmed subscriptions for the topic
  6. SubscriptionsDeleted = The number of deleted subscriptions for the topic
  7. SubscriptionsPending = The number of subscriptions pending confirmation for the topic
  8. TopicArn = The topic's ARN
  9. EffectiveDeliveryPolicy = Yhe JSON serialization of the effective delivery policy, taking system defaults into account

The following attribute applies only to server-side-encryption (https://docs.aws.amazon.com/sns/latest/dg/sns-server-side-encryption.html):

   	a) KmsMasterKeyId = The ID of an AWS-managed customer master key (CMK) for Amazon SNS or a custom CMK.
						For more information, see Key Terms (https://docs.aws.amazon.com/sns/latest/dg/sns-server-side-encryption.html#sse-key-terms)
   						For more examples, see KeyId (https://docs.aws.amazon.com/kms/latest/APIReference/API_DescribeKey.html#API_DescribeKey_RequestParameters) in the AWS Key Management Service API Reference

func (*SNS) ListEndpointsByPlatformApplication

func (s *SNS) ListEndpointsByPlatformApplication(platformApplicationArn string,
	nextToken string,
	timeOutDuration ...time.Duration) (endpointArnsList []string, moreEndpointArnsNextToken string, err error)

ListEndpointsByPlatformApplication will list endpoints by platform application, with optional nextToken for retrieving more list from a prior call

Parameters:

  1. platformApplicationArn = required, the platform application to filter for its related endpoints to retrieve
  2. nextToken = optional, if prior call returned more...token, pass in here to retrieve the related list
  3. timeOutDuration = optional, indicates timeout value for context

Return Values:

  1. endpointArnsList = string slice of endpoint ARNs under the given platform application ARN, nil if not set
  2. moreEndpointArnsNextToken = if there are more endpoints to load, this token is filled, to query more, use the token as input parameter, blank if no more
  3. err = error info if any

func (*SNS) ListPhoneNumbersOptedOut

func (s *SNS) ListPhoneNumbersOptedOut(nextToken string, timeOutDuration ...time.Duration) (phonesList []string, morePhonesNextToken string, err error)

ListPhoneNumbersOptedOut will list opted out phone numbers, with optional nextToken for retrieving more list from a prior call

Parameters:

  1. nextToken = optional, if prior call returned more...token, pass in here to retrieve the related list
  2. timeOutDuration = optional, indicates timeout value for context

Return Values:

  1. phonesList = string slice of opted out phone numbers, nil if not set
  2. morePhonesNextToken = if there are more opted out phone numbers, this token is filled, to query more, use the token as input parameter, blank if no more
  3. err = error info if any

func (*SNS) ListPlatformApplications

func (s *SNS) ListPlatformApplications(nextToken string, timeOutDuration ...time.Duration) (platformApplicationArnsList []string, moreAppArnsNextToken string, err error)

ListPlatformApplications will list platform application ARNs, with optional nextToken for retrieving more list from a prior call

Parameters:

  1. nextToken = optional, if prior call returned more...token, pass in here to retrieve the related list
  2. timeOutDuration = optional, indicates timeout value for context

Return Values:

  1. platformApplicationArnsList = string slice of platform application ARNs, nil if not set
  2. moreAppArnsNextToken = if there are more platform application ARNs, this token is filled, to query more, use the token as input parameter, blank if no more
  3. err = error info if any

func (*SNS) ListSubscriptions

func (s *SNS) ListSubscriptions(nextToken string, timeOutDuration ...time.Duration) (subscriptionsList []*SubscribedTopic, moreSubscriptionsNextToken string, err error)

ListSubscriptions will list SNS subscriptions, with optional nextToken for retrieving more list from a prior call

Parameters:

  1. nextToken = optional, if prior call returned more...token, pass in here to retrieve the related list
  2. timeOutDuration = optional, indicates timeout value for context

Return Values:

  1. subscriptionsList = *SubscribedTopic slice containing subscriptions along with its related topic, nil if not set
  2. moreSubscriptionsNextToken = if there are more subscriptions, this token is filled, to query more, use the token as input parameter, blank if no more
  3. err = error info if any

func (*SNS) ListSubscriptionsByTopic

func (s *SNS) ListSubscriptionsByTopic(topicArn string, nextToken string, timeOutDuration ...time.Duration) (subscriptionsList []*SubscribedTopic, moreSubscriptionsNextToken string, err error)

ListSubscriptionsByTopic will list SNS subscriptions by a specific topic via topicArn, with optional nextToken for retrieving more list from a prior call

Parameters:

  1. topicArn = required, list subscriptions based on this topic ARN
  2. nextToken = optional, if prior call returned more...token, pass in here to retrieve the related list
  3. timeOutDuration = optional, indicates timeout value for context

Return Values:

  1. subscriptionsList = *SubscribedTopic slice containing subscriptions along with its related topic, nil if not set
  2. moreSubscriptionsNextToken = if there are more subscriptions, this token is filled, to query more, use the token as input parameter, blank if no more
  3. err = error info if any

func (*SNS) ListTopics

func (s *SNS) ListTopics(nextToken string, timeOutDuration ...time.Duration) (topicArnsList []string, moreTopicArnsNextToken string, err error)

ListTopics will list SNS topics, with optional nextToken for retrieving more list from a prior call

Parameters:

  1. nextToken = optional, if prior call returned more...token, pass in here to retrieve the related list
  2. timeOutDuration = optional, indicates timeout value for context

Return Values:

  1. topicArnsList = string slice of topic ARNs, nil if not set
  2. moreTopicArnsNextToken = if there are more topics, this token is filled, to query more, use the token as input parameter, blank if no more
  3. err = error info if any

func (*SNS) OptInPhoneNumber

func (s *SNS) OptInPhoneNumber(phoneNumber string, timeOutDuration ...time.Duration) error

OptInPhoneNumber will opt in a SMS phone number to SNS for receiving messages (explict allow), returns nil if successful, otherwise error info is returned

Parameters:

  1. phoneNumber = required, phone number to opt in. Use E.164 format (+12095551212 where +1 is country code)
  2. timeOutDuration = optional, indicates timeout value for context

func (*SNS) Publish

func (s *SNS) Publish(topicArn string,
	targetArn string,
	message string,
	subject string,
	attributes map[string]*sns.MessageAttributeValue,
	timeOutDuration ...time.Duration) (messageId string, err error)

Publish will publish a message to a topic or target via topicArn or targetArn respectively, upon publish completed, the messageId is returned

Parameters:

  1. topicArn = required but mutually exclusive, either topicArn or targetArn must be set (but NOT BOTH)
  2. targetArn = required but mutually exclusive, either topicArn or targetArn must be set (but NOT BOTH)
  3. message = required, the message to publish, up to 256KB
  4. subject = optional, only for email endpoints, up to 100 characters
  5. attributes = optional, message attributes a) Other than defining Endpoint attributes as indicated in note below, b) attributes can also contain Message specific attributes for use for Subscriber Filter Policy and etc, *) For example, custom attribute name and value for the message can be defined in this map as metadata, so that when Subscriber receives it can apply filter policy etc (See Subscribe method Filter Policy for more info) i.e attributes["customer_interests"] = "rugby" i.e attributes["price_usd"] = 100
  6. timeOutDuration = optional, indicates timeout value for context

Message Attribute Keys:

  1. ADM a) AWS.SNS.MOBILE.ADM.TTL
  2. APNs a) AWS.SNS.MOBILE.APNS_MDM.TTL b) AWS.SNS.MOBILE.APNS_MDM_SANDBOX.TTL c) AWS.SNS.MOBILE.APNS_PASSBOOK.TTL d) AWS.SNS.MOBILE.APNS_PASSBOOK_SANDBOX.TTL e) AWS.SNS.MOBILE.APNS_SANDBOX.TTL f) AWS.SNS.MOBILE.APNS_VOIP.TTL g) AWS.SNS.MOBILE.APNS_VOIP_SANDBOX.TTL h) AWS.SNS.MOBILE.APNS.COLLAPSE_ID i) AWS.SNS.MOBILE.APNS.PRIORITY j) AWS.SNS.MOBILE.APNS.PUSH_TYPE k) AWS.SNS.MOBILE.APNS.TOPIC l) AWS.SNS.MOBILE.APNS.TTL m) AWS.SNS.MOBILE.PREFERRED_AUTHENTICATION_METHOD
  3. Custom Message Attribute Key Value Pairs a) For Use Against Subscriber Filter Policy Matching

func (*SNS) SendSMS

func (s *SNS) SendSMS(phoneNumber string,
	message string,
	timeOutDuration ...time.Duration) (messageId string, err error)

SendSMS will send a message to a specific SMS phone number, where phone number is in E.164 format (+12095551212 for example where +1 is country code), upon sms successfully sent, the messageId is returned

Parameters:

  1. phoneNumber = required, phone number to deliver an SMS message. Use E.164 format (+12095551212 where +1 is country code)
  2. message = required, the message to publish; max is 140 ascii characters (70 characters when in UCS-2 encoding)
  3. timeOutDuration = optional, indicates timeout value for context

Fixed Message Attributes Explained:

  1. AWS.SNS.SMS.SenderID = A custom ID that contains 3-11 alphanumeric characters, including at least one letter and no spaces. The sender ID is displayed as the message sender on the receiving device. For example, you can use your business brand to make the message source easier to recognize. Support for sender IDs varies by country and/or region. For example, messages delivered to U.S. phone numbers will not display the sender ID. For the countries and regions that support sender IDs, see Supported Regions and countries. If you do not specify a sender ID, the message will display a long code as the sender ID in supported countries and regions. For countries or regions that require an alphabetic sender ID, the message displays NOTICE as the sender ID. This message-level attribute overrides the account-level attribute DefaultSenderID, which you set using the SetSMSAttributes request.
  2. AWS.SNS.SMS.SMSType = The type of message that you are sending: a) Promotional = (default) – Noncritical messages, such as marketing messages. Amazon SNS optimizes the message delivery to incur the lowest cost. b) Transactional = Critical messages that support customer transactions, such as one-time passcodes for multi-factor authentication. Amazon SNS optimizes the message delivery to achieve the highest reliability. This message-level attribute overrides the account-level attribute DefaultSMSType, which you set using the SetSMSAttributes request.

func (*SNS) SetPlatformApplicationAttributes

func (s *SNS) SetPlatformApplicationAttributes(platformApplicationArn string,
	attributes map[snsplatformapplicationattribute.SNSPlatformApplicationAttribute]string,
	timeOutDuration ...time.Duration) error

SetPlatformApplicationAttributes will set or update platform application attributes, For attribute value or Json format, see corresponding notes in CreatePlatformApplication where applicable

func (*SNS) SetPlatformEndpointAttributes

func (s *SNS) SetPlatformEndpointAttributes(endpointArn string,
	attributes map[snsendpointattribute.SNSEndpointAttribute]string,
	timeOutDuration ...time.Duration) error

SetPlatformEndpointAttributes will set or update platform endpoint attributes, For attribute value or Json format, see corresponding notes in CreatePlatformEndpoint where applicable

func (*SNS) SetSubscriptionAttribute

func (s *SNS) SetSubscriptionAttribute(subscriptionArn string,
	attributeName snssubscribeattribute.SNSSubscribeAttribute,
	attributeValue string,
	timeOutDuration ...time.Duration) error

SetSubscriptionAttribute will set or update a subscription attribute, For attribute value or Json format, see corresponding notes in Subscribe where applicable

func (*SNS) SetTopicAttribute

func (s *SNS) SetTopicAttribute(topicArn string,
	attributeName snscreatetopicattribute.SNSCreateTopicAttribute,
	attributeValue string,
	timeOutDuration ...time.Duration) error

SetTopicAttribute will set or update a topic attribute, For attribute value or Json format, see corresponding notes in CreateTopic where applicable

func (*SNS) Subscribe

func (s *SNS) Subscribe(topicArn string,
	protocol snsprotocol.SNSProtocol,
	endPoint string,
	attributes map[snssubscribeattribute.SNSSubscribeAttribute]string,
	timeOutDuration ...time.Duration) (subscriptionArn string, err error)

Subscribe will allow client to subscribe to a SNS topic (previously created with CreateTopic method), the subscriptionArn is returned upon success,

if subscription needs client confirmation, then the string 'pending confirmation' is returned instead

Parameters:

  1. topicArn = required, subscribe to this topic ARN
  2. protocol = required, SNS callback protocol, so that when publish to the topic occurs, this protocol is used as callback
  3. endPoint = required, SNS callback endpoint, so that when publish to the topic occurs, this endpoint is triggered by the callback
  4. attributes = optional, map of sns subscribe attribute key value pairs
  5. timeOutDuration = optional, indicates timeout value for context

Protocols: (Key = Expected Value)

  1. http = delivery of JSON-encoded message via HTTP POST
  2. https = delivery of JSON-encoded message via HTTPS POST
  3. email = delivery of message via SMTP
  4. email-json = delivery of JSON-encoded message via SMTP
  5. sms = delivery of message via SMS
  6. sqs = delivery of JSON-encoded message to an Amazon SQS queue
  7. application = delivery of JSON-encoded message to an EndpointArn for a mobile app and device
  8. lambda = delivery of JSON-encoded message to an Amazon Lambda function

Endpoint To Receive Notifications: (Based on Protocol)

  1. http protocol = the endpoint is an URL beginning with http://
  2. https protocol = the endpoint is a URL beginning with https://
  3. email protocol = the endpoint is an email address
  4. email-json protocol = the endpoint is an email address
  5. sms protocol = the endpoint is a phone number of an SMS-enabled device
  6. sqs protocol = the endpoint is the ARN of an Amazon SQS queue
  7. application protocol = the endpoint is the EndpointArn of a mobile app and device
  8. lambda protocol = the endpoint is the ARN of an Amazon Lambda function

Subscribe Attributes: (Key = Expected Value)

  1. DeliveryPolicy = The policy that defines how Amazon SNS retries failed deliveries to HTTP/S endpoints *) example to set delivery policy to 5 retries: { "healthyRetryPolicy": { "minDelayTarget": <intValue>, "maxDelayTarget": <intValue>, "numRetries": <intValue>, "numMaxDelayRetries": <intValue>, "backoffFunction": "<linear|arithmetic|geometric|exponential>" }, "throttlePolicy": { "maxReceivesPerSecond": <intValue> } } *) Not All Json Elements Need To Be Filled in Policy, Use What is Needed, such as: { "healthyRetryPolicy": { "numRetries": 5 } }
  2. FilterPolicy = The simple JSON object that lets your subscriber receive only a subset of messages, rather than receiving every message published to the topic: *) subscriber attribute controls filter allowance, publish attribute indicates attributes contained in message *) if any single attribute in this policy doesn't match an attribute assigned to message, this policy rejects the message: { "store": ["example_corp"], "event": [{"anything-but": "order_cancelled"}], "customer_interests": ["rugby", "football", "baseball"], "price_usd": [{"numeric": [">=", 100]}] } *) "xyz": [{"anything-but": ...}] keyword indicates to match anything but the defined value ... Json element (... may be string or numeric) *) "xyz": [{"prefix": ...}] keyword indicates to match value prefixed from the defined value ... in Json element *) "xyz": [{"numeric": ["=", ...]}] keyword indicates numeric equal matching as indicated by numeric and = *) "xyz": [{"numeric": [">", ...]}] keyword indicates numeric compare matching as indicated by numeric and >, <, >=, <= *) "xyz": [{"numeric": [">", 0, "<", 100]}] keyword indicates numeric ranged compare matching as indicated by numeric and >, <, in parts *) "xyz": [{"exists": true}] keyword indicates attribute xyz exists matching
  3. RawMessageDelivery = When set to true, enables raw message delivery to Amazon SQS or HTTP/S endpoints. This eliminates the need for the endpoints to process JSON formatting, which is otherwise created for Amazon SNS metadata
  4. RedrivePolicy = When specified, sends undeliverable messages to the specified Amazon SQS dead-letter queue. Messages that can't be delivered due to client errors (for example, when the subscribed endpoint is unreachable), or server errors (for example, when the service that powers the subscribed endpoint becomes unavailable), are held in the dead-letter queue for further analysis or reprocessing *) example of RedrivePolicy to route failed messages to Dead Letter Queue (DLQ): { "deadLetterTargetArn": "dead letter sns queue arn such as arn:aws:sqs:us-east-2:12345678021:MyDeadLetterQueue" }

Subscription Confirmation Support:

  1. Http / Https Endpoints Requires Subscription Confirmation Support, See Details in URL Below: a) https://docs.aws.amazon.com/sns/latest/dg/sns-http-https-endpoint-as-subscriber.html
  2. Once Subscribe action is performed, SNS sends confirmation notification to the HTTP/s Endpoint: b) Client Upon Receipt of the SNS Notification, Retrieve Token and Respond via ConfirmSubscription method

func (*SNS) Unsubscribe

func (s *SNS) Unsubscribe(subscriptionArn string, timeOutDuration ...time.Duration) error

Unsubscribe will remove a subscription in SNS via subscriptionArn, nil is returned if successful, otherwise err is filled with error info

Parameters:

  1. subscriptionArn = required, the subscription ARN to remove from SNS
  2. timeOutDuration = optional, indicates timeout value for context

type SubscribedTopic

type SubscribedTopic struct {
	SubscriptionArn string
	TopicArn        string
	Protocol        snsprotocol.SNSProtocol
	Endpoint        string
	Owner           string
}

SubscribedTopic struct encapsulates the AWS SNS subscribed topic data

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL