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.
Let’s begin
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.
The end
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).
API keys do not work on the /v1 API:
https://firebase.google.com/docs/cloud-messaging/auth-server#authorize_http_v1_send_requests
Why didn’t you use WAS Pinpoint with FCM?
Have a look on that: https://docs.aws.amazon.com/pinpoint/latest/developerguide/send-messages-push.html
Thanks, Salah, this is a very good point π
Well, there are multiple ways to achieve the same goal using AWS.
For instance, we could add AWS SNS to that list as well.
I’d say, use what works best for you.
Take care π
Hi Rafal,
I can’t find out how to send messages to Firebase topics subscribers using AWS SNS.
In my use case there is no server that could manage device tokens. So, I’d like to send push notifications to specific device groups that subscribed to specific FCM topics. Is it anyhow possible without to use another AWS service or API?
Currently I’m getting the message content from AWS IoT Core, that forwards it via a Rule to SNS. But how to use Firebase topics instead of device tokens in SNS…
Any help would be much appreciated! π
I was able to get it right. However your code sample didn’t work for me. I’v got an error in line 5. Maybe a different Node.js version… Anyway, thank you!