https://boto3.amazonaws.com/v1/documentation/api/latest/guide/dynamodb.html

Creating a  New  Table

In order to create a new table, use the DynamoDB.ServiceResource.create_table() method:

创建新的表的方法:

import  boto3

#获取dynamoDB 服务资源

dynamodb  = boto3.resource('dynamodb')

# 创建DynamDB 表

使用create_table()方法创建表,

并且设置:

  表名称:TableName

  主键属性: keySchema

table = dynamodb.create_table(

  TableName=‘users’,

  KeySchema=[

    {

      'AttrbuteName':'username',

      'KeyType':'HASH'  #哈希

    },

    {

      'AttrbuteName':'last_name',

      'KeyType':'RANGE' #貌似列表

    }

  ],

  AttributeDefinitions=[

        {
            'AttributeName': 'username',
            'AttributeType': 'S'
        },
        {
            'AttributeName': 'last_name',
            'AttributeType': 'S'
        },

  ],

  ProvisionedThroughput={

    'ReadCapacityUnits':5,

    'WriteCapacityUnits':5

  }

)

# wait until the talble exists.

table.meta.client.get_waiter('table_exists').wait(TableName="users")

#print out some data about the table.

#打印表格数据

print(table.item_count)

这将创建一个名为users的表,该表分别具有散列和范围主键username和last_name。这个方法将返回一个DynamoDB。表资源来调用已创建表上的其他方法。

This creates a table named users that respectively has the hash and range primary keys username and last_name. This method will return a DynamoDB.Table resource to call additional methods on the created table.

Using an Existing Table 使用存在的表

It is also possible to create a DynamoDB.Table resource from an existing table:

也可以创建DynamoDB。来自现有表的表资源:

import boto3

#get the service resource.

dynamodb = boto3.resource('dynamodb')

# Instantiate a table resource object without actually实例化表资源对象
# creating a DynamoDB table. Note that the attributes of this tableare lazy-loaded: a request is not made nor are the attributevalues populated until the attributes on the table resource are accessed or its load() method is called.

#创建DynamoDB表。注意,此表的属性是延迟加载的:在访问表资源上的属性或调用其load()方法之前,

不会发出请求,也不会填充属性值。

table = dynamodb.Table('user')

# Print out some data about the table.打印一些关于表格的数据。
# This will cause a request to be made to DynamoDB and its attribute values will be set based on the response.译文:这将导致向DynamoDB发出请求,并根据响应设置其属性值。print(table.creation_date_time)

Expected Output (Please note that the actual times will probably not match up):

2015-06-26 12:42:45.149000-07:00

译文:期望输出(请注意实际时间可能不匹配):

Creating a New Item

Once you have a DynamoDB.Table resource you can add new items to the table using DynamoDB.Table.put_item():

table.put_item(

  Item={

    'username':'janedoe',

    'first_name':'Jane',

    'age':25,

    'account_type':'standard_user',

  }

)


For all of the valid types that can be used for an item, refer to Valid DynamoDB Types.

对于可用于项的所有有效类型,请参考有效的DynamoDB类型。

Valid DynamoDB Types 有效的数据类型:

Python Type

Python Type DynamoDB Type
string String (S)
integer Number (N)
decimal.Decimal Number (N)
boto3.dynamodb.types.Binary Binary (B)
boolean Boolean (BOOL)
None Null (NULL)
string set String Set (SS)
integer set Number Set (NS)
decimal.Decimal set Number Set (NS)
boto3.dynamodb.types.Binary set Binary Set (BS)
list List (L)
dict Map (M)

 
 

未完 待续

DynamoDB的更多相关文章

  1. dynamodb golang query one Item

    golang  dynamodb  query  oneItem  and unmarshal  to object // +build example package main import ( / ...

  2. golang DynamoDB sdk AccessDeniedException

    golang调用aws sdk时候提示: AccessDeniedException: User: arn:aws:sts::818539432014:assumed-role/bj-develop/ ...

  3. [转]Amazon DynamoDB – a Fast and Scalable NoSQL Database Service Designed for Internet Scale Applications

    This article is from blog of Amazon CTO Werner Vogels. -------------------- Today is a very exciting ...

  4. DynamoDB Local for Desktop Development

    Would you like to be able to write and test code that uses the Amazon DynamoDB API even if you have ...

  5. Amazon DynamoDB 概览

    1. 什么是Amazon DynamoDB DynamoDB 是一种快速.全面受管的 NoSQL 数据库服务,它能让用户以简单并且经济有效地方式存储和检索任何数据量,同时服务于任何程度的请求流量.所有 ...

  6. python--boto3 之 与dynamoDB 的基本交互,表的备份与恢复

    最近因工作需要,研究了一下boto3中dynamoDB部分,略有心得,在此总结一下. 首先是boto3的安装,在装有python和pip的机器上,运行 sudo pip install boto3 官 ...

  7. Nodejs课堂笔记-第四课 Dynamodb为何物

    本文由Vikings(http://www.cnblogs.com/vikings-blog/) 原创,转载请标明.谢谢! 我喜欢带着目标来学习新知识.因此学习nodejs过程中,不喜欢只看枯燥的语法 ...

  8. Amazon DynamoDB, 面向互联网应用的高性能、可扩展的NoSQL数据库

    DynamoDB是一款全面托管的NoSQL数据库服务.客户能够很easy地使用DynamoDB的服务.同一时候享受到高性能,海量扩展性和数据的持久性保护. DynamoDB数据库是Amazon在201 ...

  9. Aws Dynamodb数据导出到S3

    本节将描写叙述怎样从一个或多个DynamoDB的表导出数据到S3的bucket中.在运行导出之前你须要提前创建好S3的bucket. 注意 假设你还没有使用过AWS Data Pipeline,在运行 ...

随机推荐

  1. Shiro简介——《跟我学Shiro》

    地址: http://jinnianshilongnian.iteye.com/blog/2018936

  2. Python Queue(队列)

    Queue模块实现了多生产者.多消费者队列.当必须在多个线程之间安全地交换信息时,它在线程编程中特别有用,实现了所有必需的锁定语义. 一.该模块实现了三种类型的队列,它们的区别仅在于检索条目的顺序: ...

  3. Centos7上安装java

    1.默认情况下,系统安装的有jdk1.8,但是使用javac测试时会不识别这个命令,   意味着,java还是未安装好. 2.把java升级即可,此时java已经可用. yum -y install ...

  4. Thinkphp5.0支付宝支付扩展库类库大全

    Thinkphp5.0支付宝支付扩展库类库大全,包括手机网站支付.电脑网站支付.支付查询.退款.退款查询.对账单等. Thinkphp5.0支付宝调用方法: 电脑网站支付 Pagepay.php 调用 ...

  5. maven dependency的版本冲突问题

    在改造一个旧项目中,遇到各种问题. 旧项目有十多个模块,因为没有一个统一的父pom,它们对第三方的jar的版本没有统一. 虽然也存在公共的依赖模块,比如commons.util,但是,我们的模块中,有 ...

  6. ThreadLocal 原理及一些实现

    ThreadLocal = TL 网上讲TL原理很多,我大概说下自己的理解 TL其实是不是有点像全局的配置中心,static ConcurrentHashMap<Thread,value> ...

  7. Tesseract-OCR的使用记录

    参考: http://www.cnblogs.com/cnlian/p/5765871.html http://www.cnblogs.com/wzben/p/5930538.html 1.下载 Te ...

  8. oracle SQL多表查询

    SQL多表查询 1.集合理论 1.1 什么是集合 具有某种特定性质的事物的总体. 集合的特性:无序性.互异性.确定性. 一个集合可以小到从一个表中取出一行中的一列.              1 ro ...

  9. Mac谷歌浏览器跨域

    1.创建一个文件夹,这个文件夹是用来保存关闭安全策略后的用户信息的,名字可以随意取,位置也可以随意放,我用的是MyChromeDevUserData open -n /Applications/Goo ...

  10. HTTP 响应代码

    https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status HTTP 响应状态代码指示特定 HTTP 请求是否已成功完成.响应分为五类:信息响应, ...