March 9, 2018

Mobile Push Notifications on AWS

By William Welbes

push header image

Push Notifications on AWS

A great way to keep mobile app users engaged over time is to send relevant push notifications on a regular basis. If you want to keep your app away from app folder obscurity, push notifications can breath new life into the interactions with users. However, as with most prescriptions, use moderation for best results. Seek to set a great balance with your users to prevent being removed entirely.

So how do I send targeted push notifications?

There are several platforms and services that enable push, but one of the simplest and perhaps most overlooked is Amazons Web Services (AWS). One of the very first services launched on AWS was the Simple Notification Service (SNS). And not too far behind, support for mobile app push notifications via SNS was launched. Amazon does a great job of simplifying the plumbing for sending push notifications and manages the interface between your application and the platform specific push implementations.

AWS SNS is also really cheap for sending push notifications. The pricing is simple and as little as $1.00 to send a million push notifications per month.

Let's dive into a step by step guide to setup push notifications with AWS.

Create an iOS app to test push notifications

In order to test push notifications from AWS, let's start by creating a simple iOS application. AWS supports push notifications for iOS, Android, Amazon, Windows, and more. We'll focus on iOS here for simplicity, but you'll find it's a very similar process to add push in an Android app and others.

It's worth noting that Amazon has a new AWS Mobile Hub that brings together several mobile related services and APIs to make mobile integration with AWS easier. If you've used Parse in the past, it has a similar feel to it. However, for this article, I will not be using AWS Mobile Hub. The steps here would be more similar to the process you would go through to add push notifications to an existing iOS application.

Create an App ID in the Apple Developer portal

Push notifications require a unique App ID for your app.

  • Head over to to sign in to your account.
  • Navigate to Certificates, Identifiers and Profiles
  • Create a new App ID
    • Enter a name and choose your team ID
    • Choose to create an "Explicit App ID" since push notifications aren't supported on wild card app IDs
    • Enter a unique bundle identifier like "com.your-url.Push"
    • Under App Services, check the box for "Push Notifications"
    • Click Continue and you should have a new app ID to use for your app

Alright, now that we have our App ID, we're ready to create the iOS project. Keep the Apple Developer web interface around, we'll be headed back there shortly.

Create a new iOS app project in Xcode

I have published a simple project on GitHub called Push-iOS that contains the example code for setting up push notifications here:

Feel free to clone that repository and use it for reference or just use it for your sample app. If you use the sample app, remember to go in and change the bundle ID as described below to use your bundle ID and ensure that the push notifications capability is enabled.

Setup your App ID in the Xcode Project:

  • Click on the Project to open the project settings screen
  • Select the app target and enter the bundle identifier that you created above.
  • Tap over to the "Capabilities" tab and enable the push notifications for your app by turning the switch on.

    enable push image

In the sample app, I've implemented most of the logic for handling push notifications in a class called PushManager. The class does three important things:

  • Request authorization (permission) for notifications in the app
  • Register with Apple for remote push notifications and receive a device token
  • Handle push notifications received


Below is the PushManager class. You'll see calls to request authorization and if permission is granted, register for remote notification types. Once we successfully register for remote notifications with Apple, a device token is provided and stored at the class level.

Receiving push notifications

When a push notification is received on the device, iOS will present the notification as long as the app is not foregrounded. However, if the app is in the foreground, iOS will by default not present the notification. It is up to the app to change the UI accordingly or present the notification in the app. With iOS 10 and above, there is now the ability to tell iOS to still present the system UI for the notification even if the app is presented.

You'll noticed in the UNUserNotificationCenterDelegate handler, we call:


This will cause iOS to still present the notification at the system level.


We need to wire up the PushManager in the AppDelegate when the app launches.

The UNUserNotificationCenter class has a delegate that can be assigned in order to process notifications as they are received. Inside the AppDelegate, we register PushManager to be the delegate inside didFinishLaunchingWithOptions:

You'll also notice that the AppDelegate above has methods to pass along the response to:


PushManager will handle the token and results so we simply pass it along.

Build and run the Push app on an iOS device. It is worth noting that push notifications only work on iOS devices, so you won't be able to test with the Simulator. If you run on a device, you should be prompted to allow push notifications. If you accept push, after the registration with Apple completes, the device token will be shown on the main view controller of the app. The device token will also be logged to the console. You'll need that token to send your first push, so make a copy from the console log.

Setup Push on AWS

Ok. We've got our iOS app setup and ready to handle push notifications. Now let's setup AWS.

Export push certificate/key pair from Apple

First, we need to create and export a certificate key pair for AWS to use to connect to the Apple Push Notification service. In the Apple Developer portal, navigate to the Certificates, Identifiers and Profiles section again. Find the App ID that you created for the sample app in the App ID list and click on it to expand the details. Click the edit button at the bottom to edit the App ID. Scroll to the bottom of the list of capabilities to the Push Notifications area.

push configuration

There are two configuration options, Development and Production. We'll use the development environment for testing so we'll just configure that for now. The Production configuration is for push notifications sent in Apple's production environment to App Store downloaded apps.

Click on "Create Certificate" to create a new certificate/key pair to use for development push. You'll be walked through the process of generating a Certificate Signing Request in Keychain and then generating and downloading the certificate. Once you've installed the certificate in Keychain, you should export it to a .p12 file. Option click on the certificate/key pair that you generated and you'll see an option to export. Provide a password for the .p12 file and be sure to record it.

Setup in AWS console

Now we're ready to log in to AWS and setup and test push notifications. Log in to your AWS account at If you don't already have an AWS account, you can sign up for a Free Tier account that includes lots of free tier service to try out for a year.

Inside the AWS console, navigate to:

Services -> Application Integration -> Simple Notification Service

From the SNS Dashboard, click on "Create platform application". A pop up to configure your app appears. Enter an application name and select "Apple Development" from the "Push notification platform" drop down. You'll notice that there are other options in the platform drop down for "Apple production", "Google Cloud Messaging", etc. that allow you to configure other push notifications types as needed. Let's stay focused on Apple Development for now.

You'll notice the screen will now show an area for you to configure your iOS push certificate and upload the .p12 file you exported from Keychain for your push certificate/key pair.

push certificate configuration

Choose your .p12 file and enter the password you set for it and then press "Load credentials from file" and you'll see the bottom boxes populated with your certificate key pair. Click "Create platform application" to complete the setup.

You should now see the application you just created under the "Applications" area of SNS. The listing should show an ARN that you can click on. If you click on the ARN, it will load the list of application endpoints configured for your application. You can think of an endpoint as a device token in Apple's push network. It uniquely identifies a single application install on a single device. create endpoint configuration

Let's add an endpoint for your push device token. Click "Create Platform Endpoint" and a screen will pop up to prompt for the device token and user data.

Enter the device token that you copied from the iOS app log console earlier or copy it from the main screen of the app. In user data, you can enter a friendly description that will help you remember what that endpoint is.

push endpoint configuration

Ok, now that you have your endpoint confgured, there should be a checkbox all the way on the left of the list of endpoints. Check that box and the blue "Publish to Endpoint" button above the list should enable. Click that to pop up the message compose window.

sns compose message

You'll notice that you're given the option to create a message using raw formatting or JSON. The content of a push notification has a specific format to specify things like the message, sound, custom details, etc. We're going to keep it simple and just send an alert message. AWS even has a simple JSON message generator that will allow you to simply type in your message and it will generate the formatted JSON needed for you. Tap on the "JSON message generator" button and fill in the pop up with your first push message. Be creative, this is going to be popping up on your device shortly.

Once you've got your message, you can leave everything else as default and click the blue "Publish Message" button at the bottom. Boom! Your message should be on its way from AWS over to Apple and then popping up on your device.

did it work

Keep Pushin' it

Hopefully you've had some fun sending test push notifications to your device from the AWS Console. Now you're ready to integrate push into your broader application. Perhaps you have a back end system that you plan to send push notifications from. Integrate with all that AWS has to offer in order to make it super simple to send push. Use API Gateway to expose a simple API for your back end to consume and send push to remote clients. Or use AWS Lambda functions to initiate push as a response to some other event in AWS.

Looking for some help integrating with AWS? Centare has a talented team of AWS certified professionals to help.

William Welbes - Developer

About William Welbes

Will is Senior Software Engineer and consultant at Centare with a passion for building great software. With over 15 years of experience in software development, he has helped clients develop solutions across many different industries.