I'm on the AWS personalize documentation and it says access node.js code here.
More code examples (in Node.js, Python, and Go) and AWS Lambda usage guidelines are found here.
Where is here??? I'm trying to use nodejs without using lambda. How do I send the equivalent from my node server without lambda, is it even possible?
Here's the Java code.
package example;
public class ProcessKinesisRecords implements RequestHandler<KinesisEvent, Void>{
private static final String TRACKING_ID = be5aa88c-05dd-4c5e-9372-15ffa6a846b9;
private EndpointConfiguration endpointConfiguration = new EndpointConfiguration("http://concierge-gamma-events.us-west-2.amazonaws.com", "us-west-2");
private AWSConciergeEventTracking client = AWSConciergeEventTrackingClientBuilder.standard()
.withEndpointConfiguration(endpointConfiguration).build();
private final CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
@Override
public Void recordHandler(KinesisEvent event, Context context)
{
for(KinesisEventRecord rec : event.getRecords()) {
try {
// Kinesis data is Base64 encoded and needs to be decoded before being used.
String data = decoder.decode(record.getKinesis().getData()).toString();
JSONParser parser = new JSONParser();
JSONObject jsonObject = (JSONObject) parser.parse(data);
String userId = (String) jsonObject.get(USER_ID);
String sessionId = (String) jsonObject.get(SESSION_ID);
String eventType = (String) jsonObject.get(EVENT_TYPE);
long timestamp= new Date().getTime();
ByteBuffer properties = jsonObject.get(EVENT_TYPE).getBytes("UTF-8");
List<Event> eventList = new ArrayList<>();
eventList.add(new Event().withProperties(properties).withType(eventType));
TrackRequest request = new TrackRequest()
.withTrackingId(EVENT_TRACKER_ARN)
.withChannel("server")
.withUserId(userId)
.withSessionId(sessionId)
.withEventList(eventList);
client.track(request);
} catch (CharacterCodingException e) {
log.error("Error decoding data in the kinesis stream. ", e);
throw new IllegalArgumentException(e.getMessage());
} catch (ParseException e) {
log.error("Error parsing JSON input from the kinesis stream. ", e);
throw new IllegalArgumentException(e.getMessage());
} catch (Exception e) {
log.error("Error processing record. ", e);
throw new IllegalArgumentException(e.getMessage());
}
return null;
}
}