1

私はAWSのパーソナライズドキュメンテーションを読んでいて、node.jsコードにアクセスするように書かれています。

More code examples (in Node.js, Python, and Go) and AWS Lambda usage guidelines are found here.

ここに画像の説明を入力

ここはどこですか?ラムダを使わずにnodejsを使おうとしています。ラムダなしでノードサーバーから同等のものを送信するにはどうすればよいですか?

これがJavaコードです。

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;
      }
  }
4

1 に答える 1