【问题标题】:Unable to fetch the data from AWS DynamoDB无法从 AWS DynamoDB 获取数据
【发布时间】:2019-05-07 14:02:45
【问题描述】:

我想在 eclipse maven/java 中从 AWS dynamodb 获取数据,但显示以下错误

Requested resource not found (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ResourceNotFoundException; Request ID: NU99FP2PJA0PELJ9R20R7LCHSNVV4KQNSO5AEMVJF66Q9ASUAAJG)
Cannot retrieve items.
Requested resource not found (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ResourceNotFoundException; Request ID: 3DFTIT8QENPPB5L2BCQLCQJF2JVV4KQNSO5AEMVJF66Q9ASUAAJG)

我已尝试使用以下代码添加区域,但仍然显示此错误

dynamoDB.setRegion(Region.getRegion(Regions.ap-south-1));

我的代码:

package DB;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.partitions.model.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;

import com.amazonaws.services.dynamodbv2.document.DynamoDB;
import com.amazonaws.services.dynamodbv2.document.Item;
import com.amazonaws.services.dynamodbv2.document.Table;


public class Test {
       @SuppressWarnings("deprecation")
    static DynamoDB dynamoDB = new DynamoDB(new AmazonDynamoDBClient( 
                  new ProfileCredentialsProvider())); 
      // dynamoDB.setRegion(Region.getRegion(Regions.ap-south-1));  
//     Region usWest2 = Region.getRegion(Regions.US_EAST_1);
//       dynamoDB.setRegion(usWest2);
   static String tblName = "ProductList";
   public static void main(String[] args) throws IOException {
      createItems();
      retrieveItem();

   }
   private static void createItems() {
      Table table = dynamoDB.getTable(tblName);
      try {
         Item item = new Item()
            .withPrimaryKey("ID", 303)
            .withString("Nomenclature", "Polymer Blaster 4000")
            .withStringSet( "Manufacturers",
            new HashSet<String>(Arrays.asList("XYZ Inc.", "LMNOP Inc.")))
            .withNumber("Price", 50000)
            .withBoolean("InProduction", true)
            .withString("Category", "Laser Cutter");
            table.putItem(item);

         item = new Item()
            .withPrimaryKey("ID", 313)
            .withString("Nomenclature", "Agitatatron 2000")
            .withStringSet( "Manufacturers",
            new HashSet<String>(Arrays.asList("XYZ Inc,", "CDE Inc.")))
            .withNumber("Price", 40000)
            .withBoolean("InProduction", true)
            .withString("Category", "Agitator");

         table.putItem(item);
      } catch (Exception e) {
         System.err.println("Cannot create items.");
         System.err.println(e.getMessage());
      }
   }
   private static void retrieveItem() {
      Table table = dynamoDB.getTable(tblName);
      try {
         Item item = table.getItem("ID", 303, "ID, Nomenclature, Manufacturers", null);
         System.out.println("Displaying retrieved items...");
         System.out.println(item.toJSONPretty());
      } catch (Exception e) {
         System.err.println("Cannot retrieve items.");
         System.err.println(e.getMessage());
      }
   }
}

【问题讨论】:

  • 我还在 DynamoDB 中创建了表名作为产品列表(手动)

标签: amazon-web-services aws-lambda amazon-dynamodb dynamodb-queries


【解决方案1】:

您的代码看起来不错,因此请确保您的表确实存在于ap-south-1 区域中。

【讨论】:

  • 感谢您的回复。该表存在于 ap-south-1 区域中。
猜你喜欢
  • 1970-01-01
  • 2019-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多