我想在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());
}
}
}
答案 0 :(得分:0)
您的代码看起来不错,因此请确保您的表确实存在于ap-south-1
区域中。