AWS DynamoDB Python - 无法识别boto3 Key()方法(查询)(AWS DynamoDB Python - boto3 Key() methods not recognized (Query))
我正在使用Lambda(Python)来查询我的DynamoDB数据库。 我正在使用boto3库,我能够创建一个“等效”查询:
这个脚本有效:
import boto3 from boto3.dynamodb.conditions import Key, Attr import json def create_list(event, context): resource = boto3.resource('dynamodb') table = resource.Table('Table_Name') response = table.query( TableName='Table_Name', IndexName='Custom-Index-Name', KeyConditionExpression=Key('Number_Attribute').eq(0) ) return response
但是,当我将查询表达式更改为:
KeyConditionExpression=Key('Number_Attribute').gt(0)
我收到错误:
"errorType": "ClientError", "errorMessage": "An error occurred (ValidationException) when calling the Query operation: Query key condition not supported"
根据这[1]资源,“gt”是Key()的方法。 有没有人知道这个库是否已经更新,或者除了“eq”之外还有哪些其他方法?
[1] http://boto3.readthedocs.io/en/latest/reference/customizations/dynamodb.html#ref-dynamodb-conditions
- - - - -编辑 - - - - -
我也尝试使用旧方法:
response = client.query( TableName = 'Table_Name', IndexName='Custom_Index', KeyConditions = { 'Custom_Number_Attribute':{ 'ComparisonOperator':'EQ', 'AttributeValueList': [{'N': '0'}] } } )
这很有用,但是当我尝试时:
response = client.query( TableName = 'Table_Name', IndexName='Custom_Index', KeyConditions = { 'Custom_Number_Attribute':{ 'ComparisonOperator':'GT', 'AttributeValueList': [{'N': '0'}] } } )
...这是行不通的。
为什么EQ是在这些情况下工作的唯一方法? 我不确定文档中缺少什么。
I am using Lambda (Python) to query my DynamoDB database. I am using the boto3 library, and I was able to make an "equivalent" query:
This script works:
import boto3 from boto3.dynamodb.conditions import Key, Attr import json def create_list(event, context): resource = boto3.resource('dynamodb') table = resource.Table('Table_Name') response = table.query( TableName='Table_Name', IndexName='Custom-Index-Name', KeyConditionExpression=Key('Number_Attribute').eq(0) ) return response
However, when I change the query expression to this:
KeyConditionExpression=Key('Number_Attribute').gt(0)
I get the error:
"errorType": "ClientError", "errorMessage": "An error occurred (ValidationException) when calling the Query operation: Query key condition not supported"
According to this [1] resource, "gt" is a method of Key(). Does anyone know if this library has been updated, or what other methods are available other than "eq"?
[1] http://boto3.readthedocs.io/en/latest/reference/customizations/dynamodb.html#ref-dynamodb-conditions
---------EDIT----------
I also just tried the old method using:
response = client.query( TableName = 'Table_Name', IndexName='Custom_Index', KeyConditions = { 'Custom_Number_Attribute':{ 'ComparisonOperator':'EQ', 'AttributeValueList': [{'N': '0'}] } } )
This worked, but when I try:
response = client.query( TableName = 'Table_Name', IndexName='Custom_Index', KeyConditions = { 'Custom_Number_Attribute':{ 'ComparisonOperator':'GT', 'AttributeValueList': [{'N': '0'}] } } )
...it does not work.
Why would EQ be the only method working in these cases? I'm not sure what I'm missing in the documentation.
原文:
最满意答案
Index
未定义one.use与i
。使用document.ready
更好的包装代码。在文档加载后执行该功能$(document).ready(function(){ var Sites = [ {"country_name": "Denmark", "latitude": 56, "longitude": 10, "status": "OK", "site_name": "FLS Denmark", "Model_Number": "12345"}, { "country_name": "Zaire", "latitude": -20, "longitude": 30, "status": "OK", "site_name": "FLS Zaire", "Model_Number": "67890" }, { "country_name": "Vietnam", "latitude": 16, "longitude": 106, "status": "NO", "site_name": "FLS Vietnam", "Model_Number": "1111" }] var DefaultText = ""; var i; for (i = 0; i < Sites.length; i++) { DefaultText += '<div class="rightcontainer">'; DefaultText += '<img id="productimage" src="src/images/retrofit.png" onclick="DisplayProfileCard();"/>'; DefaultText += '<div id="imagedetail">'; DefaultText += '<span class="details">Product Type:'+ Sites[i].Model_Number +'</span>'; DefaultText += '<span class="details">Version / Size <img class="row_one_icon lightbulb_icon" id="lightbulb" src="src/images/lightbulb1.png" onClick="LightBulb()" /><img id="convert" class="row_one_icon arrow_icon" src="src/images/arrow_Off.png" onClick="Conversion()"/><img id="lightning" class="row_one_icon" src="src/images/lightningOff.png" onClick="Lightning()"/><img id="bullseye" class="row_one_icon bullseye" src="src/images/bullseye_off.png" onClick="BullsEye()"/></span>'; DefaultText += '<span class="details">Estimated annual Spend <img class="row_one_icon ribbon" src="src/images/ribbon1.png"/><img class="row_one_icon map" src="src/images/map1.png"/><img class="row_one_icon paper_stack" id="paper" src="src/images/paper_stack_Off.png" onclick="PaperStack()"/><img class="row_one_icon chain" id="chain" src="src/images/chain_Off.png" onClick="ChainLink()"/></span>'; DefaultText += '<span class="details">Site name / manufacturer</span>'; DefaultText += '<span class="details">Selling Sales Eng</span>'; DefaultText += '</div>'; DefaultText += '</div>'; } $('#searchcontainer').append(DefaultText); })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="searchcontainer"></div>
Index
was undefined one.use withi
.And better wrap code withdocument.ready
.its perform the function after document loaded$(document).ready(function(){ var Sites = [ {"country_name": "Denmark", "latitude": 56, "longitude": 10, "status": "OK", "site_name": "FLS Denmark", "Model_Number": "12345"}, { "country_name": "Zaire", "latitude": -20, "longitude": 30, "status": "OK", "site_name": "FLS Zaire", "Model_Number": "67890" }, { "country_name": "Vietnam", "latitude": 16, "longitude": 106, "status": "NO", "site_name": "FLS Vietnam", "Model_Number": "1111" }] var DefaultText = ""; var i; for (i = 0; i < Sites.length; i++) { DefaultText += '<div class="rightcontainer">'; DefaultText += '<img id="productimage" src="src/images/retrofit.png" onclick="DisplayProfileCard();"/>'; DefaultText += '<div id="imagedetail">'; DefaultText += '<span class="details">Product Type:'+ Sites[i].Model_Number +'</span>'; DefaultText += '<span class="details">Version / Size <img class="row_one_icon lightbulb_icon" id="lightbulb" src="src/images/lightbulb1.png" onClick="LightBulb()" /><img id="convert" class="row_one_icon arrow_icon" src="src/images/arrow_Off.png" onClick="Conversion()"/><img id="lightning" class="row_one_icon" src="src/images/lightningOff.png" onClick="Lightning()"/><img id="bullseye" class="row_one_icon bullseye" src="src/images/bullseye_off.png" onClick="BullsEye()"/></span>'; DefaultText += '<span class="details">Estimated annual Spend <img class="row_one_icon ribbon" src="src/images/ribbon1.png"/><img class="row_one_icon map" src="src/images/map1.png"/><img class="row_one_icon paper_stack" id="paper" src="src/images/paper_stack_Off.png" onclick="PaperStack()"/><img class="row_one_icon chain" id="chain" src="src/images/chain_Off.png" onClick="ChainLink()"/></span>'; DefaultText += '<span class="details">Site name / manufacturer</span>'; DefaultText += '<span class="details">Selling Sales Eng</span>'; DefaultText += '</div>'; DefaultText += '</div>'; } $('#searchcontainer').append(DefaultText); })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="searchcontainer"></div>
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
用这个: for (var i = 0; i < response.Album_list.length; i++) { var album = response.Album_list[i]; console.log(album); } 关于in循环的文档 因为我看到你正在使用jQuery。 你可以这样做: $.each(response.Album_list, function(index, album) { console.log(album); }); Use this: fo ...
-
如何循环json列表中的元素Ajax / Javascript(How to loop over elements in a json list Ajax/Javascript)[2023-01-26]
基于你的javascript,json看起来像{ "routers" :[ {"os": "4.4.4.4", "name": "DNSROOTSERVER"}]} Based on your javascript the json shoud look like { "routers" :[ {"os": "4.4.4.4", "name": "DNSROOTSERVER"}]} -
您可以使用简单的循环语句: success: function(data){ var i, l; for (i = 0, l = data.length; i < l; i++) { // access the object: data[i] console.log(data[i]); } } 这是最有效的方式。 You can use a simple loop statement: success: function(data) ...
-
你得到了循环错误的基本语法: for (json.messages in object){ alert(object.message); } 假设你想循环json.messages的消息,并且使用除了object之外的名称作为可能是内置系统的名称,那么实际上它会按如下方式编写它: for (alertMessage in json.messages){ alert(alertMessage); } 另见https://developer.mozilla.org/en-US ...
-
为什么不...... if ( obj.DataArray[i].Category == 'Delicious Treats' ) addOption(document.drop_list.item, obj.DataArray[i].Price, obj.DataArray[i].ItemName); Why not just... if ( obj.DataArray[i].Category == 'Delicious Treats' ) addOption(document.dr ...
-
你正在用新值替换,代码应该是 var newrow = ''; for (var i=0; i"; } you are replacing with new value, code sho ...