Mallow's Blog

How to Send Push notifications using Laravel and AWS SNS

Push notification is the process of delivering information from the back end application to end user’s mobile device without any request from the end user. We can send the push notifications from Laravel application using AWS SNS service easily.

AWS SNS (Simple Notification Service) is a flexible, fully managed push notification service provided by Amazon web services. Using this, we can send messages to individuals or large numbers of recipients. Amazon SNS makes it simple and cost effective to send push notifications to mobile device users, email recipients or even send messages to other distributed services.

In this blog, we will see about sending push notifications to android devices with FCM (Firebase Cloud Messaging).

FCM is a cross-platform messaging solution that allows us to send messages for both Android and Apple devices.

Implementation

Step 1 :

Firstly, we need to create an project in Firebase and get the Legacy server key for Cloud messaging.

Step 2 :

Then create an application in AWS SNS with GCM platform.

How to Send Push notifications using Laravel and AWS SNS

It will create an ARN for your application.

Then add the this ARN in your .env file

ANDROID_APPLICATION_ARN=arn:aws:sns:us-east-1:9273842649560:app/GCM/Test-Application

Step 3 :

In laravel, We need to use the following package,

https://github.com/aws/aws-sdk-php-laravel

This makes the developers to access Amazon Web Services in Laravel code.

And Add your AWS credentials in aws.php config file.

Step 4 :

Then we need to get the device tokens with the corresponding platform (Android) from User App.

Here, we have got the device token and generated the end point ARN for our Mobile using the Android application arn and stored in the database.

Step 5 :

Finally, we can send Push notifications using the already generated end point ARN.

We can also pass the the custom data through push notifications.

It is more efficient if you send notifications using queues.

More about queues, refer this link

https://laravel.com/docs/5.4/queues

So in this post we have seen in detail about how to send a push notification to Android Devices using laravel, FCM and SNS. In future posts we will see some other feature that can be integrated with Laravel and AWS so work in perfect manner.

 

Anandhan S,
Junior Developer,
Mallow Technologies.

2 Comments

  1. Ahmed Almulki

    can you guide me how can I send web notification instead of Android ?

  2. Prabaharan

    Dear Mallow Tech,
    Can you help how to integrate AWS SNS Push Notitication using YII 2.

Leave a Reply

%d bloggers like this: