Is it possible to push messages to a subset of the app installs with SNS.
When publishing to a topic by default all subscribers get the notification.
As you mention, when publishing to a topic, all (valid) endpoints that are subscribed receive the message. There's no conditional operations here - it's all or nothing.
Your options for sending to a smaller subset are:
Maintain a number of SNS topics that group the users together the way you want. This requires subscribing and unsubscribing endpoints to your topics from your own code.
You can send directly specific endpoints from your own code, using the Publish API Command. You would specify an endpointArn for the TargetArn property, and do not specify a value for the TopicArn property. You would need to manage these groupings of endpoints in your code and simply loop through each desired recipient and publish to its endpoint.
Related
I am working on an app on AWS that needs to send text messages to customers. At times, the app just needs to send a single text message (AWS Transactional SMS may help here), at times it may need to text different groups of people (AWS doesn't seem to have a solution for this use case). It all depends on what the user is doing on the app.
I have explored the possibility of using SNS, but it requires users to be subscribed to a topic, which doesn't work for my use case. I have explored the possibility of using AWS Pinpoint, but it also doesn't seem to apply to my use case. I could use Twilio, but I would prefer to stay within AWS (Additionally, Twilio runs on AWS)
What is the best way to send text messages in the USA through AWS that doesn't require subscription to a topic?
If someone seeking for the answer of this Qn:
You can send SMS in 2 ways in AWS SNS.
Subscribe to a topic that is created in AWS SNS and send sms to all those numbers who had the subscription
Send SMS directly to a mobile number
What you need is the 2nd one.
I will demonstrate here how to do that with Ruby language.
Install the gem aws sns:
gem install aws-sdk-sns
require 'aws-sdk-sns'
1.Set SNS client
#sns_client = Aws::SNS::Client.new(
region: ENV['AWS_SNS_REGION'],
access_key_id: ENV['AWS_SNS_ACCESS_KEY'],
secret_access_key: ENV['AWS_SNS_SECRET_KEY']
)
2.Set SNS client attributes
#sns_client.set_sms_attributes({
attributes: {
'DefaultSenderID' => SENDER_ID,
'DefaultSMSType' => SMS_TYPE
}
})
3.Publish SMS
otp = (1000..9999).to_a.sample
#sns_client.publish({
phone_number: #mobile_no,
message: "#{OTM_MSG} #{otp}"
})
thats it!
OTM_MSG: ‘Your message comes here’
SMS_TYPE : ‘Transactional’ or ‘Promotional’
If you want to send OTP / bank transactions, then it is ‘Transactional’. Else if you want to send some promotional sms of your product then it is ‘Promotional’
SENDER_ID: is the sender id that you have already registered if you want to use your own sender id.
If you don't have sender id skip the step 2 - Set SNS client attributes
AWS_SNS_REGION, AWS_SNS_ACCESS_KEY, AWS_SNS_SECRET_KEY - are the credentials of your AWS account from where you would like to use SNS.
See the AWS documentation for this here:
https://docs.aws.amazon.com/sns/latest/dg/sms_publish-to-phone.html
It also provides code for Java language.
If you want to know more I have written an article here:
https://railsdrop.com/2021/03/04/aws-sns-how-to-send-sms/
Use the Publish action from the SNS service to send a text to a single phone without a topic. You could repeatedly call Publish to send texts to multiple phones.
https://docs.aws.amazon.com/sns/latest/dg/sms_publish-to-phone.html
Use the CreateTopic, Subscribe, and Publish actions from the SNS service to send a text to a multiple phones at once (uses a Topic).
https://docs.aws.amazon.com/sns/latest/dg/sms_publish-to-topic.html
I want to develop an app that allows the users of the app (sellers on Amazon), to send me a notification when they receive an order on Amazon (a notification containing informations about the order).
Is it possible?
Maybe only the seller can receive notifications about his account.
I think, if it's possible, I need a MWS and a AWS account.
In the documentation of MWS (https://docs.developer.amazonservices.com/en_US/notifications/Notifications_Overview.html), there is:
The Amazon MWS push notifications enable you to receive information
that is relevant to your business with Amazon without having to poll
the Amazon MWS service. Instead, the information is sent directly to
you when an event occurs to which you are subscribed. For more
information about how to subscribe to receive notifications, see
Subscriptions Overview in the Amazon MWS Subscriptions API section
reference.
Then, in the 'Subscriptions API' section:
The Amazon MWS Subscriptions API section enables you to subscribe to
receive notifications that are relevant to your business with Amazon.
With the operations in the Subscriptions API section, you can register
to receive important information from Amazon without having to poll
the Amazon MWS service. Instead, the information is sent directly to
you when an event occurs to which you are subscribed.
To receive notifications, you must first create and register a
Destination, such as an Amazon Simple Queue Service (Amazon SQS)
queue. Then, you create a Subscription for the NotificationType that
you want to receive, such as a notification when another Seller has
changed their offer for an item that you also sell. Finally, verify
that Amazon is able to send notifications to your Destination by
calling the SendTestNotificationToDestination operation.
Not at this time. The only notification options are AnyOfferChangedNotification, which sends an SQS message when any one of the top 20 offers for an ASIN changes, and FulfillmentOrderStatusNotification, which notifies you if there is a multi channel order status chance, and FeePromotionNotification.
This hasn't changed since I started using the AnyOfferChangedNotification several years ago.
One idea is to create an app that uses the Orders API periodically to check for orders, then you can have the app create the SQS message (or use another service altogether). This would then notify you of a new order.
Our apps are being developed for both Android and iOS. We are using AWS SNS Mobile Push to push messages to both GCM and APNS. The back end is PHP and so it uses the AWS PHP SDK.
Until now, our system has been saving 1 Endpoint ARN per user. We then broadcast a Mobile Push message directly to this Endpoint ARN.
The question:
It would be strange if a user were logged into our app on multiple devices and did not receive push notifications on all of them. So - we're going to have to change something.
How, in AWS Mobile Push, is the concept of 'one user, multiple devices (and potentially multiple platforms) handled?
Does our system have to maintain a one-to-many association of user-to-EndpointARNs (i.e. start saving multiple EndpointARNs per user so that we may push messages to all of them sequentially)?
Or should I be looking into the 'Topics' concept that Mobile Push provides (I'm confused here - do some people use one topic per user, and then push messages to the topic itself?)..
Lastly - I guess as a bonus question - is it normal for people using the PHP AWS SDK to include both APNS and GCM attributes in the Message payload array? We haven't been keeping track of 'which type of device each user uses'. We've just been saving an Endpoint ARN per user. And I guess the thought was to just cover all our platform bases (APNS, APNS_SANDBOX, GCM) when we're pushing a message to an endpoint.
I've been doing a lot of searching on the 'one user with multiple devices' topic re: Mobile Push with AWS SNS, and really the results have been quite unhelpful.
Help please :(
Thanks!
Once you send SNS Push message , you will get success or failure reason.
Could you please check your logs and share to identify exact issue.
Cloudwatch :
SNS publishes Cloudwatch metrics for number of messages published, number of successful notifications, number of failed notifications and size of data published. Metrics are available on per application basis. You can access Cloudwatch metrics via AWS Management Console or CloudWatch APIs.
Direct addressing:
Direct addressing allows you to deliver notifications directly to a single endpoint, rather than sending identical messages to all subscribers of a topic. This is useful if you want to deliver precisely targeted messages to each recipient. When you register device tokens with SNS, SNS creates an endpoint that corresponds to the token. You can publish to the token endpoint just as you would publish to a topic. You can direct publish either the text of your notification, or a platform-specific payload that takes advantage of platform-specific features such as updating the badge count of your app. Direct addressing is currently only available for push notifications endpoints.
Official documentation, "When a topic is created, Amazon SNS will assign a unique ARN (Amazon Resource Name) to the topic.
https://aws.amazon.com/sns/faqs/
I have a solution for this issue as you already know ARN is associated with single device token so you must be manage it own your own to send push to same user with multiple device.
My approach is to create 2 table in mysql or whatever database you are using
1. For APNS or, APNS_SANDBOX having details like user_id(local), device token, endpoint ARN, status etc (EG : sns_apns)
2. Same for GCM or BAIDU you have to create a table having user details with endpoint ARN(EG : sns_gcm)
Now every time when you send push to a particular user just write a code something like this
Switch($platform) {
case 'APNS':
case 'APNS_SANDBOX':
Select all users from sns_apns by login id.
Create a message and send it to all users having same user id
case 'GCM':
Select all users from sns_gcm by login id.
Create a message and send it to all users having same user id
}
I haven't tried this but to solve your problem I would keep a map of the user's cognito userID and corresponding endpoint ARN for each major app defining transaction done by the user. If the endpoint already exist then no need to save it. But if for this userID another endpoint ARN is notice then save, update, add or associate this new endpointARN with userID in DynamoDB as a #Document attribute. Then at anytime just broadcast to all endpointARN associated to the userID in DynamoDB.
The mysampleapp mobile hub example codes are useful for quick manipulation. For android:
Get the endpointARN in app like this:
PushManager pushManager;
String userDeviceEndPoint;
pushManager = AWSMobileClient.defaultMobileClient().getPushManager();
userDeviceEndPoint = pushManager.getEndpointArn();
You can update DynamoDB using the update save behaviour to ignore if an already existing endpoint is noticed for the user:
DynamoDBMapper mapper = new DynamoDBMapper(ddbClient, new DynamoDBMapperConfig(DynamoDBMapperConfig.SaveBehavior.UPDATE_SKIP_NULL_ATTRIBUTES));
Not sure how to do this in PHP though. Hope this idea helps.
We're using AWS SNS (Simple Notification Services) as one of the mechanisms of sending out notifications for users. That means, there are notifications sent through SMS (using AWS SNS) / Emails / automated calls.
But any time, if a user unsubscribes from any of these three methods, We should stop sending further alerts to the user in all the three modes.
Currently I don't have a way in API to check if a subscription request has been opted-out (by sending a STOP message), so that we can block the other two modes of communications as well.
Is it possible, in SNS? I've tried looking into the list of API, console and Amazon Forums.
I've figured out that this below behaviour of AWS SNS (for SMS end points) can be a workaround.
Although currently there is no way of getting a list of endpoints (users) who unsubscribe by responding STOP to 30304 (Amazon's short number.)
But, when we subscribe a user for a topic, AWS creates a subscription record with subscriptionArn = "PendingConfirmation"
If the user responds STOP (opts out), the subscription record is deleted from the topic. If the user subscribes to it, the subscription's subscriptionArn changes to some valid ARN (Amazon's resource Number) from "PendingConfirmation".
ListSubscriptionsByTopic API lists the user subscription even if it is in "PendingConfirmation" state.
So for now, only way to know if a user has unsubscribed from the topic would be, maintaining a list of users with their end points (phone numbers / email ids) and comparing it at later point of time with the list of available list of subscriptions. If something has disappeared, it means they've unsubscribed.
Of course, it can't be real-time. But this is the only workaround that is available for now.
As an additional info, if a subscription is pending for more than 72 hours, it is automatically deleted.
I see AWS publish API for sending push notifications to devices.
http://docs.aws.amazon.com/sns/latest/api/API_Publish.html
According to:
https://aws.amazon.com/blogs/aws/push-notifications-to-mobile-devices-using-amazon-sns/
We can
"Send messages directly to a specific device by calling the Publish function with the device’s ARN. You can easily scale this to handle millions of users by storing the endpoint ARNs in Amazon DynamoDB and using multi-threaded code on the server."
If I want to send push notifs to 100K users (who haven't registered to a specific topic), is there a multi-publish (or batch-publish) API, where I don't need to call the "Push notifications" API for every single user?
probably not. the devices need to be registered (i.e. for SNS you actually have to create the endpoint for each device).
After you have the endpoint you can subscribe them to either one or multiple SNS endpoint and start publishing notifications through them.