I have an iOS app with a backend build by MobileHub
with API Gateway
, Lambda
, and DynamoDB
.
I noticed that the SNS
function of MobileHub
has been replaced by Pinpoint
, and I would like to create a notification system using this new service.
When a user creates a new post through API Gateway
, a lambda function will be triggered and I suppose I can send a notification to the subscribers by Pinpoint
.
But I cannot find any example or reference doc in the official website of Pinpoint
.
Do you have any resource for this scenario or any idea? Thank you very much!
Amazon Simple Notification Service (SNS) sends notifications two ways, A2A and A2P.
To integrate the latest version of an AWS SDK into your Lambda function's deployment package, create a Lambda layer, and then add it to your function. You can use either the AWS Command Line Interface (AWS CLI) or the Lambda console to create a Lambda layer and add it to your function.
Changes This release of the Amazon Pinpoint API introduces MMS support for SMS messages. Changes This release of the Amazon Pinpoint API introduces support for integrating recommender models with email, push notification, and SMS message templates.
Depends what you mean by notification, I assume you would like to send a push notification to a particular user (Pinpoint endpoint).
Pinpoint stores each device associated with a user as an "endpoint", generally created by the AWS client side analytics library (e.g. amplify analytics).
With the amplify analytics library, I call updateEndpoint
so I can specify a userId
that is available to Lambda, as well as the device token and remove optOut
so user can receive the push notification:
Address
- The token generated from user accepting push notification permission (iOS)optOut
- NONE
so they can receive push notificationsuserId
- unique id for user (Cognito's sub)Now you can send a push notification, using the userId
and the Pinpoint SDK.
const sendMessagesParams = {
ApplicationId: process.env.PINPOINT_APP_ID,
SendUsersMessageRequest: {
Users: {
[receiverUserId]: {}
},
MessageConfiguration: {
APNSMessage: {
Action: 'OPEN_APP',
Title: 'Message received',
SilentPush: false,
Body: `You have a new message`
},
GCMMessage: {
Action: 'OPEN_APP',
Title: 'Message received',
SilentPush: false,
Body: `You have a new message`
}
}
}
};
console.log('sendMessagesParams', JSON.stringify(sendMessagesParams));
pinpoint.sendUsersMessages(sendMessagesParams, (sendMessagesErr, sendMessagesData) => console.log('push sent')
For your particular scenario, I set up a DynamoDB stream and trigger a Lambda when a record changes within the table. You may need to add the IAM permissions manually once the lambda is created.
Sources
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With