<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AWS &#8211; Zhijun Chen</title>
	<atom:link href="https://zhijunchen.com/tag/aws/feed/" rel="self" type="application/rss+xml" />
	<link>https://zhijunchen.com</link>
	<description></description>
	<lastBuildDate>Sat, 29 Jan 2022 14:31:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.4</generator>

<image>
	<url>https://zhijunchen.com/wp-content/uploads/2021/03/cropped-my-site-icon-1-32x32.png</url>
	<title>AWS &#8211; Zhijun Chen</title>
	<link>https://zhijunchen.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Mobile Push Notification Overview Using AWS SNS And React Native</title>
		<link>https://zhijunchen.com/mobile-push-notification-overview-using-aws-sns-and-react-native/</link>
		
		<dc:creator><![CDATA[Zhijun Chen]]></dc:creator>
		<pubDate>Sat, 29 Jan 2022 14:29:49 +0000</pubDate>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[React Native]]></category>
		<category><![CDATA[SNS]]></category>
		<guid isPermaLink="false">https://zhijunchen.com/?p=165</guid>

					<description><![CDATA[Recently I spent some time looking into mobile push notification architecture mainly focused on Android and iOS. Before I go into explaining how mobile push notification works, here are some terminologies I used throughout the post: Platform &#8211; These are services provided by mobile device builders (e.g. Apple, Google, Amazon) that transport the messages to [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Recently I spent some time looking into mobile push notification architecture mainly focused on Android and iOS. Before I go into explaining how mobile push notification works, here are some terminologies I used throughout the post:</p>



<p><strong>Platform</strong> &#8211; These are services provided by mobile device builders (e.g. Apple, Google, Amazon) that transport the messages to the end devices. The Platforms offer device registration, app token creation and management, and the delivery channel for notifications to be delivered to devices. There are several different services that you can use to send push notifications to the users of your applications. The platform you use largely depends on which app store your customers use to obtain your app. The most common platforms are <a rel="noreferrer noopener" href="https://developer.apple.com/notifications/" data-type="URL" data-id="https://developer.apple.com/notifications/" target="_blank">Apple Push Notification service (APNs)</a>, <a rel="noreferrer noopener" href="https://firebase.google.com/docs/cloud-messaging" data-type="URL" data-id="https://firebase.google.com/docs/cloud-messaging" target="_blank">Firebase Cloud Messaging (FCM)</a>, <a rel="noreferrer noopener" href="https://push.baidu.com/" data-type="URL" data-id="https://push.baidu.com/" target="_blank">Baidu Cloud Push</a>, and <a href="https://developer.amazon.com/docs/adm/overview.html" data-type="URL" data-id="https://developer.amazon.com/docs/adm/overview.html" target="_blank" rel="noreferrer noopener">Amazon Device Messaging (ADM)</a>.</p>



<p><strong>Provider</strong> &#8211; The Provider allows app registration and messaging to be coordinated by your mobile apps backend system, to allow for event or schedule based interactions from your backend with your mobile app. They typically utilise underlining mobile platforms to communicate with your mobile app. Examples are <a href="https://docs.aws.amazon.com/sns/latest/dg/welcome.html" data-type="URL" data-id="https://docs.aws.amazon.com/sns/latest/dg/welcome.html" target="_blank" rel="noreferrer noopener">AWS SNS</a>, <a href="https://aws.amazon.com/pinpoint/" data-type="URL" data-id="https://aws.amazon.com/pinpoint/" target="_blank" rel="noreferrer noopener">AWS Pinpoint</a>, <a href="https://onesignal.com/" data-type="URL" data-id="https://onesignal.com/" target="_blank" rel="noreferrer noopener">OneSignal</a>, <a href="https://docs.expo.dev/push-notifications/overview/" data-type="URL" data-id="https://docs.expo.dev/push-notifications/overview/" target="_blank" rel="noreferrer noopener">Expo Push API</a>, etc.</p>



<p><strong>Client</strong> &#8211; This is the mobile application running on a physical device or simulator.</p>



<p>The overall architecture looks like the following:</p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="812" height="422" src="//i3.wp.com/zhijunchen.com/wp-content/uploads/2022/01/mobile-push-Overall-Architecure.drawio.png" alt="" class="wp-image-166" srcset="https://zhijunchen.com/wp-content/uploads/2022/01/mobile-push-Overall-Architecure.drawio.png 812w, https://zhijunchen.com/wp-content/uploads/2022/01/mobile-push-Overall-Architecure.drawio-300x156.png 300w, https://zhijunchen.com/wp-content/uploads/2022/01/mobile-push-Overall-Architecure.drawio-768x399.png 768w" sizes="(max-width: 812px) 100vw, 812px" /><figcaption>Mobile Push Notification Architecture Overview</figcaption></figure>



<p>As you can see from the diagram, your service/push trigger will talk to AWS SNS which uses FCM/APNs to push notifications to clients. Note that FCM could also push notifications to iOS devices according to their documentation, but underneath it is also using APNs which you still need to setup.</p>



<p>The first thing you need to do is to create a project in your chosen mobile platform, then use the project information to create a <strong>platform application</strong> in SNS. The push notification workflow using SNS is shown as below:</p>



<figure class="wp-block-image size-full"><img decoding="async" width="701" height="651" src="//i1.wp.com/zhijunchen.com/wp-content/uploads/2022/01/mobile-push-Workflow-Workflow.png" alt="" class="wp-image-169" srcset="https://zhijunchen.com/wp-content/uploads/2022/01/mobile-push-Workflow-Workflow.png 701w, https://zhijunchen.com/wp-content/uploads/2022/01/mobile-push-Workflow-Workflow-300x279.png 300w" sizes="(max-width: 701px) 100vw, 701px" /><figcaption>SNS mobile push notification workflow</figcaption></figure>



<ol><li>Your mobile app sets up secure connection with mobile platforms to register for app push notification and request a device and app specific <strong>device token</strong></li><li>The platform returns the device token back to your mobile app</li><li>Your mobile app could pass the device token along with other information to your service</li><li>You service calls AWS SNS to set up an <strong>application endpoint</strong> using the device token and additional user data</li><li>SNS returns application endpoint response back to your service to save for future reference</li><li>When your service wants to push a notification, it will call SNS application endpoint with the message for the platform</li><li>SNS calls mobile platform to deliver the message</li><li>Mobile platform pushes the message to your mobile client</li></ol>



<p>There are several react native mobile libraries you can use for step 1-2:</p>



<ul><li>If you are using <a rel="noreferrer noopener" href="https://expo.dev/" data-type="URL" data-id="https://expo.dev/" target="_blank">Expo</a> to create your mobile application, you can use their <a rel="noreferrer noopener" href="https://www.npmjs.com/package/expo-notifications" data-type="URL" data-id="https://www.npmjs.com/package/expo-notifications" target="_blank">expo-notifications</a> to receive notifications and call <a rel="noreferrer noopener" href="https://docs.expo.dev/versions/latest/sdk/notifications/#getdevicepushtokenasync-devicepushtoken" target="_blank">Notifications.getDevicePushTokenAsync()</a> to retrieve native token instead of Expo token. At the time of writing, this approach does not work with Expo Go app and the apple environment is default to production. This library works best with <a rel="noreferrer noopener" href="https://docs.expo.dev/push-notifications/overview/" data-type="URL" data-id="https://docs.expo.dev/push-notifications/overview/" target="_blank">Expo Push API</a> so you might need to put in extra effort to set it up and it also requires physical device in both Apple and Android for push notification to work. One advantage of using this library is that you write in pure JavaScript without having to set up Android and iOS native code.</li><li>If you are using reactive native, there are <a rel="noreferrer noopener" href="https://github.com/zo0r/react-native-push-notification" data-type="URL" data-id="https://github.com/zo0r/react-native-push-notification" target="_blank">react-native-push-notification</a> (<strong>Warning: No longer actively maintained</strong>) and <a rel="noreferrer noopener" href="https://github.com/wix/react-native-notifications" target="_blank">react-native-notifications</a>.</li></ul>



<p><strong>Note: Apple always requires physical devices for push notification while Android simulator could be used to test locally.</strong></p>



<p>One important thing I found out through the research was that there are so many solutions out there and each of them gives you pros and cons. It is better to gather your requirements first then pick the one most suitable for you.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
