Send a notification by Lambda function with AWS Pinpoint

aws pinpoint api
aws pinpoint nodejs
aws pinpoint push notifications
aws pinpoint lambda
aws pinpoint send sms
aws pinpoint sdk
aws pinpoint deep linking
aws pinpoint python example

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!

Step 3: Create Lambda functions - Amazon Pinpoint, This solution uses two Lambda functions. This section shows you how to create and configure these functions. Later, you set up API Gateway� Step 3: Set up AWS Lambda. In this step, we create an AWS Lambda function and then integrate it with the order_detail table. After, we will check the order and send a notification if large enough. 1. Navigate to Service>Lambda. 2.Click on Create function. 3. Select runtime as Python 3.6. Select an execution role.

This is certainly possible with Amazon Pinpoint. You can find the Javascript SDK documentation here.

There are 2 modes of sending with Pinpoint.

  1. Direct send - This is effectively the same as what SNS has traditionally been. You need a device token and you can send directly to your push provider using that token.
  2. Segmentation sends - This mode is slightly different and assumes that you have loaded all your devices into Pinpoint via the Mobile SDK as part of your app, or via an S3 Import. The benefit here is that you can segment your devices and send to that segment (e.g. 'Ryans Friends').

So in your Lambda backed API you can choose to either send directly to subscribers (if you have their addresses) or potentially an entire segment of subscribers (if you have loaded your endpoints into Pinpoint).

Send push notifications - Amazon Pinpoint, Functional cookies help us provide useful site features, remember your preferences, and display relevant content. Approved third parties may set these cookies� This solution uses two Lambda functions. This section shows you how to create and configure these functions. Later, you set up API Gateway and Amazon Pinpoint to execute these functions when certain events occur. Both of these functions create and update endpoints in the Amazon Pinpoint project that you specify.

I was struggling a lot getting a lambda function working, so please see this answer as an addition to the answer from Dylan w.

Client
import PushNotification from '@aws-amplify/pushnotification';
import Analytics from '@aws-amplify/analytics';

PushNotification.onRegister((token) => {

    Analytics.updateEndpoint({
        address: token,
        channelType: 'APNS',
        optOut: 'NONE',
        // Customized userId
        userId: "e236e3ea-bas9-4eae-967e-0eb9bcaca26d" // Example
    })

});
Lambda function
'use strict';

const AWS = require('aws-sdk');

exports.handler = async (event, context) => {

  var pinpoint = new AWS.Pinpoint();

  const sendMessagesParams = {
    ApplicationId: <YOUR_APPLICATION_ID>, // Find it in Pinpoint->All projects
    SendUsersMessageRequest: {
        Users:{<USER_ID>:{}}, // The same userId as set on the client. This way you can "follow" people if they switch device
        MessageConfiguration:{
          APNSMessage:{
            Action:"OPEN_APP",
            Title:"Message received",
            Body:"You have a new message"
        }
      }
    }
  };

  return await new Promise( (resolve, reject) => {

    pinpoint.sendUsersMessages(sendMessagesParams, (sendMessagesErr, sendMessagesData) => {
      if(sendMessagesErr) reject(sendMessagesErr)
      if(sendMessagesData) resolve(sendMessagesData)
    });

  });

};

Note that the call to pinpoint is wrapped in a promise. Because pinpoint.sendUserMessages accepts a callback, the execution is continued (async nature of Node), which will shut down the lambda function and you will get no output from the callback function or receive a notification, without awaiting the function to finish.

Step 4: Create the Lambda function - Amazon Pinpoint, This solution uses a Lambda function to update customers' endpoint records based on the preferences that they provide on the web form. In your contact flow editor, under Integration, drag an Invoke AWS Lambda function block, choose the header of the block to edit it, select your sendPinpointSMS Lambda function, enter 8 seconds for the Timeout value, and choose Save.

Send real-time alerts using Amazon Pinpoint, After, we will check the order and send a notification if large enough. 1. Navigate to Service>Lambda. 2.Click on Create function. 3. Select runtime� When Amazon Pinpoint invokes a Lambda function for a recommender model, it sends a payload that contains the configuration and other settings for the campaign or journey that's sending the message. The payload includes an Endpoints object, which is a map that associates endpoint IDs with endpoint definitions for message recipients.

Creating custom channels in Amazon Pinpoint, Next, write your AWS Lambda function by doing the following: and “ mobiletargeting:*” to send SMS messages through Amazon Pinpoint. with other blog posts like this to identify repeat callers and send a text notification. 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.

Using Amazon Pinpoint to send text messages in Amazon Connect , Example Lambda function. Your Lambda function processes the event data sent by Amazon Pinpoint, and it returns� When an Amazon Pinpoint campaign executes this Lambda function, Amazon Pinpoint sends the function a list of segment members. The function counts the number of endpoints of each ChannelType .

Comments
  • How are you instantiating pinpoint? I have followed all the documentation but am being informed that sendUsersMessages is undefined. sendMessages works fine..
  • I do specify an API version and the region pinpoint is in: const pinpoint = new AWS.Pinpoint({ apiVersion: '2016-12-01', region: process.env.PINPOINT_REGION }); The process.env constants are listed in the "Environment variables" section below lambda code
  • In your Lambda function, do you need to provide AWS credentials or an IAM role? Simply nothing happens when i try to run the code you listed
  • @Attaque depends how you implement, for pinpoint I created a mobiletargeting full access policy, to allow sending of messages, also the stream iam role. { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "mobiletargeting:*" ], "Resource": "*" } ] }
  • Should I store the ARNs in my DynamoDB table? Or Pinpoint will help me to manage ARNs. If I want to send a message to Ryans Friends segment. How could I recognize this segment is for Ryan this Cognito identity?