Push notifications are back here again. In this case I’m going to send it from the clouds.
In this simple example I’ll use AWS Lambda function with API Gateway integration and Firebase Cloud Messaging service in order to send push notifications to the topic subscribers.
At first we’re creating a new Node.js AWS Lambda function.
The function is sending push notification to the topic (which is called common) subscribers. Proper notification data is obtained from the event body.
Please note you’ll need OAuth FCM token (FIREBASE_API_KEY variable – how to get the token? Read more here) and your Firebase project identifier.
Then we’ll need to create API Gateway resource. If you already have one you can create a POST method with Lambda proxy integration. Pass your specific function name there.
Then you can send your very first test event.
If everything is okay you should receive your notification. It even supports emojis 🙂.
Now we can deploy the API and use the endpoint.
And that’s it. You can now send your push notifications using AWS Lambda function.
Please note that this is just a simple example. In production environment you’ll have to handle OAuth tokens refreshing (read more about it).