兰州网站制作cheng,网站发布,wordpress 旅行主题,网站开发公司目前主营业务AWS DynamoDB是一个NOSQL数据库。
可以通过IAM直接控制权限#xff0c;和AWS其他服务连用非常方便。 DynamoDB的几个概念
Partition Key#xff1a;分区键。如果没有Sort key#xff0c;那么Partition Key必须唯一#xff0c;如有Sort key#xff0c;Partition Key可以重…AWS DynamoDB是一个NOSQL数据库。
可以通过IAM直接控制权限和AWS其他服务连用非常方便。 DynamoDB的几个概念
Partition Key分区键。如果没有Sort key那么Partition Key必须唯一如有Sort keyPartition Key可以重复。
Sort key: 排序键。
Composite KeyPartition Key和Sort key的合称是一个逻辑概念。
GSI: 独立于Partition Key和Sort key之外的第二套索引机制。可以创建多个GSI。 用Boto3查询DyanmoDB
使用GSI来查询数据需要指定indexname
这里假设分区键叫key1排序键叫sortkeyGSI叫gsi-index
import boto3
from boto3.dynamodb.conditions import Attr, Keydef query_app(self, key1: str, sortkey: str):response self.table.query(IndexNamegsi-index,KeyConditionExpression Key(key1).eq(key1) Key(sortkey).begins_with(sortkey),ScanIndexForward False)code response.get(ResponseMetadata).get(HTTPStatusCode)if code 200:logging.info(fquery item successfully!)return response.get(Items)else:logging.warning(fquery item fail!, response is {code}) query和scan的区别
query是利用key来查询。推荐。scan是全表扫描以后再过滤。、 参考资料
PowerPoint Presentation (sides-share.s3.cn-north-1.amazonaws.com.cn)