简体   繁体   English

iOS AWS DynamoDB无法运行请求

[英]iOS AWS DynamoDB can't run a request

I've been struggling with connecting to the AWS DynamoDB with my iOS app. 我一直在努力使用我的iOS应用程序连接到AWS DynamoDB。 I am frustrated with the lack of tutorials/documentation on the DynamoDB (I guess it is still fairly new). 我对DynamoDB上缺少教程/文档感到沮丧(我想它仍然相当新)。 But I ahve been trying to follow Amazon's User Preference Tutorial I am trying to just connect to the database and read something or write something but I am getting an exception thrown. 但我一直在尝试关注亚马逊的用户偏好教程我试图只是连接到数据库并阅读或写一些东西,但我得到一个异常抛出。

AmazonCredentials *creds;
creds = [creds initWithAccessKey:MY_ACCESS_KEY withSecretKey:MY_SECRET_KEY];
AmazonDynamoDBClient *ddb = [[AmazonDynamoDBClient alloc] initWithCredentials:creds];
DynamoDBGetItemRequest *request = [[DynamoDBGetItemRequest alloc]
    initWithTableName:@"Users" andKey:[[DynamoDBKey alloc] initWithHashKeyElement:
    [[DynamoDBAttributeValue alloc] initWithS:@"Chase"]]];
DynamoDBGetItemResponse *response = [ddb getItem:request]; //THROWING THE EXCEPTION HERE!
NSMutableDictionary *user = response.item;
NSLog(@"%@",user);

The output reads: Terminating app due to uncaught exception 'AmazonServiceException', reason: '' 输出显示:由于未捕获的异常'AmazonServiceException'而终止应用程序,原因:''

The only thing that I changed from what the tutorial has done is the way I set up my user credentials and the line that throws the exception, the tutorial has: 我从教程中所做的唯一改变是我设置用户凭据的方式和抛出异常的行,教程具有:

DynamoDBCreateTableResponse *response = [[AmazonClientManager ddb] getItem:request];

I couldn't find any AmazonClientManager class anywhere, but the AmazonDynamoDBClient class seems to have the same method, so I am assuming that it should work (this could very well be the assumption that is breaking my code). 我无法在任何地方找到任何AmazonClientManager类,但AmazonDynamoDBClient类似乎有相同的方法,所以我假设它应该工作(这很可能是我的代码破坏的假设)。 I don't know if Amazon still supports that class because I can't find it in any documentation either. 我不知道亚马逊是否仍然支持该类,因为我也无法在任何文档中找到它。

Also, before I get yelled at, I know that I shouldn't be handing out my own credentials in the app. 此外,在我被大吼之前,我知道我不应该在应用程序中分发我自己的凭据。 I will change this later. 我稍后会改变它。 I am just trying to get to a sanity state for now. 我现在正试图进入理智状态。

You need to change these lines 您需要更改这些行

AmazonCredentials *creds;
creds = [creds initWithAccessKey:MY_ACCESS_KEY withSecretKey:MY_SECRET_KEY];

to this 对此

AmazonCredentials *creds = [[AmazonCredentials alloc] initWithAccessKey:MY_ACCESS_KEY withSecretKey:MY_SECRET_KEY];

Also, AmazonClientManager is not a part of the SDK. 此外,AmazonClientManager不是SDK的一部分。 It's a part of the sample app and returns an instance of AmazonDynamoDBClient. 它是示例应用程序的一部分,并返回AmazonDynamoDBClient的实例。 It's included in the sample project. 它包含在示例项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM