Ошибка: не удалось найти сервис JobId: AmazonRekognition;Код статуса: 400; - PullRequest
0 голосов
/ 16 декабря 2018

Я использую этот лямбда-код Java, предоставленный AWS, для обнаружения меток в видео:

https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/code_examples/java_examples/stored_video/java-lambda-handler-sns.java

//Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.)

package com.amazonaws.lambda.demo;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.SNSEvent;
import java.util.List;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.rekognition.AmazonRekognition;
import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder;
import com.amazonaws.services.rekognition.model.GetLabelDetectionRequest;
import com.amazonaws.services.rekognition.model.GetLabelDetectionResult;
import com.amazonaws.services.rekognition.model.LabelDetection;
import com.amazonaws.services.rekognition.model.LabelDetectionSortBy;
import com.amazonaws.services.rekognition.model.VideoMetadata;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;



public class JobCompletionHandler implements RequestHandler<SNSEvent, String> {

   @Override
   public String handleRequest(SNSEvent event, Context context) {

      String message = event.getRecords().get(0).getSNS().getMessage();
      LambdaLogger logger = context.getLogger(); 

      // Parse SNS event for analysis results. Log results
      try {
         ObjectMapper operationResultMapper = new ObjectMapper();
         JsonNode jsonResultTree = operationResultMapper.readTree(message);
         logger.log("Rekognition Video Operation:=========================");
         logger.log("Job id: " + jsonResultTree.get("JobId"));
         logger.log("Status : " + jsonResultTree.get("Status"));
         logger.log("Job tag : " + jsonResultTree.get("JobTag"));
         logger.log("Operation : " + jsonResultTree.get("API"));

         if (jsonResultTree.get("API").asText().equals("StartLabelDetection")) {

            if (jsonResultTree.get("Status").asText().equals("SUCCEEDED")){
               GetResultsLabels(jsonResultTree.get("JobId").asText(), context);
            }
            else{
               String errorMessage = "Video analysis failed for job " 
                     + jsonResultTree.get("JobId") 
                     + "State " + jsonResultTree.get("Status");
               throw new Exception(errorMessage); 
            }

         } else
            logger.log("Operation not StartLabelDetection");

      } catch (Exception e) {
         logger.log("Error: " + e.getMessage());
         throw new RuntimeException (e);


      }

      return message;
   }

   void GetResultsLabels(String startJobId, Context context) throws Exception {

      LambdaLogger logger = context.getLogger();

      AmazonRekognition rek = AmazonRekognitionClientBuilder.standard().withRegion(Regions.US_EAST_1).build();

      int maxResults = 1000;
      String paginationToken = null;
      GetLabelDetectionResult labelDetectionResult = null;
      String labels = "";
      Integer labelsCount = 0;
      String label = "";
      String currentLabel = "";

      //Get label detection results and log them. 
      do {

         GetLabelDetectionRequest labelDetectionRequest = new GetLabelDetectionRequest().withJobId(startJobId)
               .withSortBy(LabelDetectionSortBy.NAME).withMaxResults(maxResults).withNextToken(paginationToken);

         labelDetectionResult = rek.getLabelDetection(labelDetectionRequest);

         paginationToken = labelDetectionResult.getNextToken();
         VideoMetadata videoMetaData = labelDetectionResult.getVideoMetadata();

         // Add labels to log
         List<LabelDetection> detectedLabels = labelDetectionResult.getLabels();

         for (LabelDetection detectedLabel : detectedLabels) {
            label = detectedLabel.getLabel().getName();
            if (label.equals(currentLabel)) {
               continue;
            }
            labels = labels + label + " / ";
            currentLabel = label;
            labelsCount++;

         }
      } while (labelDetectionResult != null && labelDetectionResult.getNextToken() != null);

      logger.log("Total number of labels : " + labelsCount);
      logger.log("labels : " + labels);

   }


}

При проверке результатов в cloudwatch я получаю сообщение об ошибке:


05:23:48
Rekognition Video Operation:=========================

05:23:48
Job id: "f647269c4f8bab504cfc9e50a2d89593e463c31755e3bdf41fac18b8be603d65"

05:23:48
Status : "SUCCEEDED"

05:23:48
Job tag : null

05:23:48
Operation : "StartLabelDetection"

05:23:49
*Error: Could not find JobId (Service: AmazonRekognition; Status Code: 400; Error Code: ResourceNotFoundException; Request ID: c4d9bbe0-00f2-11e9-8aa2-21ecd18719a6)*

05:23:49
com.amazonaws.services.rekognition.model.ResourceNotFoundException: Could not find JobId (Service: AmazonRekognition; Status Code: 400; Error Code: ResourceNotFoundException; Request ID: c4d9bbe0-00f2-11e9-8aa2-21ecd18719a6): java.lang.RuntimeException java.lang.RuntimeException: com.amazonaws.services.rekognition.model.ResourceNotFoundException: Could not find JobId (Service: AmazonRekognition; S

05:23:49
END RequestId: 4f531035-00f2-11e9-96d7-f55b78da9771

05:23:49
REPORT RequestId: 4f531035-00f2-11e9-96d7-f55b78da9771  Duration: 941.37 ms Billed Duration: 1000 ms Memory Size: 1024 MB   Max Memory Used: 98 MB

Я использую учетную запись root и настроил AWS, как описано в «Руководстве разработчика Rekognition по созданию инструментария AWS для Eclipse Lambda».

Проблема с кодомили что-то еще?

1 Ответ

0 голосов
/ 24 декабря 2018

После консультации с форумом AWS Rekognition мне посоветовали убедиться, что я вызываю функцию из того же региона, как указано в функции:

AmazonRekognition rek = AmazonRekognitionClientBuilder.standard (). WithRegion ( Regions.US_EAST_1 ). Build ();

...