- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
以下代码在尝试访问我的 AWS DynamoDB 表时会生成此错误消息。该表称为“客户”,该列称为“电子邮件”,值为“james@gmail.com”。我直接从此处提供的 AWS 示例中复制了此代码 https://github.com/awsdocs/aws-doc-sdk-examples 。我做错了什么吗?我在这上面浪费了好几天时间,尝试不同的事情:-(
任何帮助表示赞赏。谢谢,
错误消息
{"message":"Expected params.Key to be a map","code":"InvalidParameterType","time":"2019-03-13T23:05:59.231Z"}
NodeJs 代码
const express = require('express')
const app = express()
const port = 8080
var AWS = require('aws-sdk');
app.get('/test', (req, res) => {
// Set the region
AWS.config.update({region: 'eu-west-1'});
// Create DynamoDB document client
var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
var key = { email: 'james@gmail.com' };
ddb.getItem({
TableName: 'customers',
Key: key
}, function(err, data) {
if (err) {
res.send(err);
}
else {
res.send(data);
}
});
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
DynamoDB 表
再次尝试我也收到此错误消息
{"message":"There were 20 validation errors:\n* InvalidParameterType: Expected params.Key['email'] to be a structure\n* UnexpectedParameter: Unexpected key '0' found in params.Key['email']\n* UnexpectedParameter: Unexpected key '1' found in params.Key['email']\n* UnexpectedParameter: Unexpected key '2' found in params.Key['email']\n* UnexpectedParameter: Unexpected key '3' found in params.Key['email']\n* UnexpectedParameter: Unexpected key '4' found in params.Key['email']\n* UnexpectedParameter: Unexpected key '5' found in params.Key['email']\n* UnexpectedParameter: Unexpected key '6' found in
更新
var key = { email: 'james@gmail.com' };
ddb.getItem({
TableName: 'customers',
Key: key
}, function(err, data) {
if (err) {
res.send(err);
}
else {
res.send(data);
}
});
更新
const express = require('express')
const app = express()
const port = 8080
var AWS = require('aws-sdk');
app.get('/test', (req, res) => {
AWS.config.update({region: 'eu-west-1'});
var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
var params = {
TableName: 'customers',
Key: {
'email': {S: 'james@gmail.com'}
},
};
ddb.getItem(params, function(err, data) {
if (err) {
res.send(err);
} else {
res.send(data);
}
});
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
错误结果
{"message":"The provided key element does not match the schema","code":"ValidationException","time":"2019-03-14T19:26:13.602Z","requestId":"EIGKLLNEJR2DKSET6787JHQLC7VV4KQNSO5AEMVJF66Q9ASUAAJG","statusCode":400,"retryable":false,"retryDelay":46.10177725769697}
最佳答案
第二次编辑:我完全错过了您没有使用 DocumentClient (正如 Vladyslav Ulenko 指出的那样),因此为了完整性更新了下面的答案。
<小时/>您有两个选择:
第一个选项使用带有 getItem
方法的 DynamoDB 服务对象,如下所示:
...
var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
var params = {
TableName: 'customers',
Key: {
'email': {S: 'james@gmail.com'} . // <-- pay attention to data type 'S'
},
};
ddb.getItem(params, function(err, data) {
if (err) {
res.send(err);
} else {
res.send(data);
}
});
指定 DynamoDB 数据(属性值)类型 here (查找表编码/解码映射。
第二个选项是使用DocumentClient
。在这种情况下,您不必担心编码(marshal)和取消编码(marshal)请求/响应数据(DynamoDB 值与 JavaScript 类型之间的转换)。在这种情况下,您的代码如下所示:
...
var docClient = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'});
var params = {
TableName: 'customers',
Key: {'email': 'james@gmail.com'}
};
docClient.get(params, function (err, data) {
if (err) {
res.send(err);
} else {
res.send(data);
}
});
...
<小时/>
我建议您使用 DocumentClient
而不是 DynamoDB'
getItem` 操作,因为它完全处理所有数据转换!
如果不这样做,您还需要处理响应数据类型,例如:
data.Items.forEach(function(element, index, array) {
console.log(element.FristName.S + " " + element.LastName.S);
});
不确定你是否愿意
<小时/>第三次编辑:现在您已经完成了上述操作,您将收到错误:
“提供的关键元素与架构不匹配”
这意味着您使用的 key 与架构上定义的 key 不同,同样来自 documentation :
For the primary key, you must provide all of the attributes. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key.
并确保将其中提到的所有 key 都放入 key 参数中
正如 Vladyslav 在其答案的评论部分中指出的那样,如果您需要使用不是主键的属性查找项目,则需要使用 scan
操作而不是 getItem
。您可以在 documentation 中找到示例
关于node.js - 将 getItem 与 DynamoDB 和 Node aws-sdk 库一起使用时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55152509/
我正在细读 http://www.khronos.org/网站,只找到了 OpenCL 的头文件(不是我不关心的 OpenGL)。如何获取 OpenCL SDK? 最佳答案 AMD 的 ATI Str
Android 项目中最低(最低 sdk)和最高(目标 sdk)级别是否有任何影响。这些东西是否会影响项目的可靠性和效率。 最佳答案 没有影响,如果您以 SDK 级别 8 为目标,那么您的应用将以 9
“min sdk version/target sdk version”和“compile sdk version”有什么区别?我知道 min 和 target sdk 是什么意思,但是 compil
我正在尝试运行 Dji Mobile-Sdk-Android:https://github.com/dji-sdk/Mobile-SDK-Android使用 dji 网站上的说明:https://de
我目前正在向我的 iPhone 应用程序添加新的 Facebook iOS sdk 3.1.1。我看到 sdk 有重大变化。例如。我的旧 sdk 创建一个 Facebook 对象并从 FBReques
我最近刚刚下载了 Xcode 4.6 with mac 10.8.4 with iOS 6.0 SDK package,我立即注意到我无法使用我的 iPhone 3Gs with iOS 4.6 进行
我尝试下载 OpenCL SDK。但是没办法。我有一个 AMD GPU,所以我在谷歌上搜索了 AMD SDK,但是来自谷歌的所有链接和一些教程都被破坏了,不可能通过 AMD 开发者网站找到 sdk。
安装 Google Cloud SDK 后,当我运行时 gcloud 授权登录 我收到一条错误消息: Your browser has been opened to visit: https://a
我一直在 nvidia 网站上搜索 GPU 计算 SDK,因为我正在尝试构建具有 cuda 支持的点云库 (PCL)。但是,在 nvidia 网站上,我只能找到工具包的链接,而不是 SDK 的单个下载
Closed. This question needs to be more focused。它当前不接受答案。 想改善这个问题吗?更新问题,使其仅关注editing this post一个问题。 2
当我打开 Android SDK 管理器时,会出现一个屏幕“选择要安装的包”。它列出了一堆带有绿色复选标记(已经安装)的软件包,还有一些带有 x's 的软件包,它们没有安装。如果我选择“全部接受”,它
在开发过程中,我发布了 SDK 21 Lollipop,但我无法在我的 KitKat 设备上使用它。应用程序非常简单,我只将 SDK 用于动画和 Material 设计,但是当我尝试对 Play 商店
enter image description here friend 们好 在使用 Linux、jenkins 和 docker 探索 dotnet 核心时,我遇到了构建问题,该问题在标题“/usr
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我创建了一个flutter项目,运行flutter packages get,输出如下:【二】flutter包搞定等待另一个 flutter 命令释放启动锁...第二次运行“flutter packa
这个问题在这里已经有了答案: What are the Android SDK build-tools, platform-tools and tools? And which version sh
我使用 Corona SDK 已经快一年了,并且开发了几个简单的游戏。我现在正在寻找的是在 Corona SDK 中创建 3D 幻觉的某种方法。如果有人有 Corona 3D 方面的经验,我将不胜感激
我有一个CLDC 1.1 / MIDP 2.0项目,可以使用Java ME SDK 3.2很好地进行编译。 最近,我已将Java SE升级到8,结果Java ME SDK开始在Windows启动时显示
有没有办法以编程方式控制连接到华擎主板的 RGB 照明?我知道华硕有一个 Aura SDK,但华擎是否也有一个用于他们的硬件? 如果是,我在哪里可以找到它? 最佳答案 没有用于华擎多彩的 sdk。但是
如何使用 crm 2011 sdk 和 XrmServiceContext 创建事务? 在下一个示例中,'new_brand' 是一些自定义实体。我想创建三个品牌。第三个拥有错误的 OwnerID g
我是一名优秀的程序员,十分优秀!