我正在尝试将我的应用程序连接到DynamoDB。我已按照亚马逊推荐的方式设置了一切。但我仍然一遍又一遍地得到同样的错误:
7-21 11:02:29.856 10027-10081/com.amazonaws.cognito.sync.demo E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
Process: com.amazonaws.cognito.sync.demo, PID: 10027
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:304)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException: Requested resource not found (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ResourceNotFoundException; Request ID: GIONOKT7E3AMTC4PO19CPLON93VV4KQNSO5AEMVJF66Q9ASUAAJG)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:710)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:385)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:196)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:2930)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.updateItem(AmazonDynamoDBClient.java:930)
at com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBMapper$SaveObjectHandler.doUpdateItem(DynamoDBMapper.java:1173)
at com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBMapper$2.executeLowLevelRequest(DynamoDBMapper.java:873)
at com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBMapper$SaveObjectHandler.execute(DynamoDBMapper.java:1056)
at com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBMapper.save(DynamoDBMapper.java:904)
at com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBMapper.save(DynamoDBMapper.java:688)
at com.amazonaws.cognito.sync.Utils.FriendsSyncManager.initalize_credentialprovider(FriendsSyncManager.java:43)
at com.amazonaws.cognito.sync.ValU.FriendListActivity$SyncFriends.doInBackground(FriendListActivity.java:168)
at com.amazonaws.cognito.sync.ValU.FriendListActivity$SyncFriends.doInBackground(FriendListActivity.java:160)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
可能是什么解决方案?
答案 0 :(得分:31)
似乎你需要添加:
ddbClient.setRegion(Region.getRegion(Regions.EU_WEST_1));
// Add correct Region. In my case its EU_WEST_1
在以下行之后:
AmazonDynamoDBClient ddbClient = new AmazonDynamoDBClient(credentialsProvider);
现在它有效。该表已成功创建。 祝你有个美好的一天,谢谢!
答案 1 :(得分:0)
您需要检查几件事:
private static String awsSecretKey = "your_secret_key"; //get it in AWS web UI
private static String awsAccessKey = "your_access_key"; //get it in AWS web UI
client.setRegion(Region.getRegion(Regions.US_EAST_1));
您可以从AWS Web Console获取此值。 Details
如果没有,请检查您的代码
@DynamoDBTable(tableName = "Event")
public class Event implements Serializable {
public static final String CITY_INDEX = "City-Index";
public static final String AWAY_TEAM_INDEX = "AwayTeam-Index";
并从AWS Console或其他方式手动创建表(在我的情况下为Event)和索引(在我的情况下为City-Index,AwayTeam-Index)。请注意-表格和索引名称可能会有所不同。
答案 2 :(得分:0)
伴随着@Yuliia Ashomok的回答
AWS C ++ SDK 1.7.25
Aws::Client::ClientConfiguration clientConfig;
clientConfig.region = Aws::Region::US_WEST_2;
答案 3 :(得分:0)
如果使用Spring Boot,则可以通过应用程序属性配置区域:
在src / main / resources / application.yaml
中cloud:
aws:
region:
static: eu-west-1
答案 4 :(得分:0)
因为这个问题与平台无关。对于从.NET / C#遇到相同问题的任何人...
您可以在构造函数中使用Endpoint实例化客户端:
AmazonDynamoDBClient client = new AmazonDynamoDBClient(credentials, Amazon.RegionEndpoint.USEast1 );
我本以为这是从您的AWS Profile中引入的,但是似乎不能,尽管您可以执行以下操作,其中Profile是从您的SharedCredentialsFile导入的:
new AmazonDynamoDBClient(credentials, profile.Region );
答案 5 :(得分:0)
如果您确定已经在 DynamoDB 中创建了表,但仍然收到此错误。这意味着您的地区可能不正确。只需查看您的 AWS 门户右上角的个人资料下拉菜单。另一个下拉菜单将为您提供选择您所在地区的选项。现在再次使用正确的区域执行此过程。
希望这有效。这对我有用。
答案 6 :(得分:0)