我是DynamoDB
的新手,我想用它来存储与S3对象匹配的键字符串。这是我上传字符串的代码:
AmazonCredentials *amazonCreds = [[AmazonCredentials alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey: SECRET_KEY];
AmazonDynamoDBClient *dClient = [[AmazonDynamoDBClient alloc] initWithCredentials: amazonCreds];
[dClient setEndpoint: [AmazonEndpoints s3Endpoint:AP_SOUTHEAST_1 secure: YES]];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
[[DynamoDBAttributeValue alloc] initWithS: req.key],
@"QuoteKey",
nil];
DynamoDBPutItemRequest *dReq = [[DynamoDBPutItemRequest alloc] initWithTableName:@"TestQuotesTable" andItem: [dict mutableCopy]];
DynamoDBPutItemResponse *dRes = [dClient putItem: dReq];
但是,当我进入控制台并输入表格时,该项目未上传...。我的代码有问题吗?当我第一次在
DynamoDB
中创建表时,默认键/属性名称是“ QuoteKey”,因此一切都应该没问题。我的代码有问题吗?谢谢
最佳答案
您正在将客户端的端点设置为S3端点,而不是DynamoDB。您将要替换:
[dClient setEndpoint: [AmazonEndpoints s3Endpoint:AP_SOUTHEAST_1 secure: YES]];
具有以下内容:
[dClient setEndpoint: [AmazonEndpoints ddbEndpoint:AP_SOUTHEAST_1 secure: YES]];