SNS Batch Publish - amazon-web-services

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.

Related

Difference between a device subscribing to an SNS topic, and a lambda function subscribing to a topic?

Im currently trying to design a scalable push notification service, which can send notifications to 5-10 mil users in a very short time. I came across two AWS related architectures which got me confused.
Use case: Send a notification to all the users.
1) Each device subscribes to an SNS topic, and if we want to send a push to all users, we just publish to the topics endpoint. And SNS handles the rest(sending to the million users)
2) Lambda functions are subscribed to SNS topics. We send a message to an SNS topic containing all the device tokens/batches, and then lambda calls APN/Firebase endpoints.
I fail to see in what case the second architecture would be beneficial compared to the first?
Mobile push notification :
sns endpoint will created based on user device token and you will get device token from Adm,Fcm,etc like push notification platform sdk and you can trigger push notification to perticular user based sns endpoint because each device have different endpoint and it created user device token and you will have track user device token and endpoint and userId and you can able to see aws sns mobile push notification console
1) you can create manually also
2) you can create endpoint using programmatically
you can refer below sdks to create via code https://docs.aws.amazon.com/sns/latest/dg/mobile-push-api.html
Lamda push notification
You can create sns topic in sns console and you can subscribe which lambda you want deliver notification
basically if you want connect one lamda to another lamda you can use those case
example 1:
you have micro service for sending otp to user and micro service deployed in different lambda and application recives sending otp request your application main lamda and now you need call otpservice lamda so you can create one sns topic and under subscription you can subscripe otp micro service lamda so main lamda will trigger otp service sns endpoint it will deliver notification micro service lamda

How to send notifications to a specific user with AWS SNS?

I am developing an app like Dominoes. In which, I would like to send a Push notification to the Customer, when his/her Order is prepared.
I had been using OneSignal to do so (through sending notification to a particular player id), and now we would like to do it with AWS SNS Service, as we are using bunch of different AWS Services too.
We don't want any marketing/bulk push notifications, the SNS Service would do only one thing - send a particular message from the Restaurants' Mobile (using REST API), and it would reach the Customer's mobile.
With OneSignal, we used to give the PlayerID/UserID of the receiver. Does this method apply to AWS SNS too? Also, we could only work with HTTPS POST requests in our platform.
Any help is appreciated :)
Thanks!

Amazon MWS Push Notifications

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.

AWS Mobile Push with users that may be logged into multiple devices

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.

Amazon SNS Mobile Push to sub set of devices

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.