Search code examples
amazon-web-servicesamazon-personalize

not able to send real time data into aws personalize


I created an api endpoint to send my user interaction data into the personalize recommendation engine in real time. However, when I tried to send the post request to this endpoint I get an error saying AccessDeniedException: User: arn:aws:iam::21847893275720:user/demo-user is not authorized to perform: personalize:PutEvents because no identity-based policy allows the personalize:PutEvents action

How do I solve this issue? Do I need to add additional parameters in the putEventsParams?

my api function looks something like this

import AWS from 'aws-sdk';  

var personalizeevents = new AWS.PersonalizeEvents({
    accessKeyId: process.env.AWS_ACCESS_KEY_ID,
    secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
    region: process.env.AWS_REGION});

const streamInteractions = async (req, res) => {
    const { eventType, userId, trackingId } = req.body;
        var eventDate = new Date();
        var putEventsParams= {
            'sessionId': '1', 
            'trackingId': trackingId,
            'userId': userId,
            eventList: [
                {
                  'eventType': eventType, 
                  'sentAt': eventDate
                },
            ]
        }
        personalizeevents.putEvents(putEventsParams, function (err, data) {
          if (err) {
                console.log(err, err.stack); // an error occurred
          }
          else{     
                console.log(data);           // successful response
          }
        });
    res.json('Done!');
}


Solution

  • As the error message indicates, your user requires the personalize:PutEvents action to be able to call the putEvents API. Add a policy such as the following to your user in IAM.

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": "personalize:PutEvents",
                "Resource": [
                    "*"
                ]
            }
        ]
    }