dynamoDB学习02

4-13学习记录
明天预计是Security Best Practices
可能会对本篇进行补充

Setting Up DynamoDB

配置本地的dynamoDB,获取对应的镜像并运行

#获取镜像
docker pull amazon/dynamodb-local
#运行
docker run -d -p 8000:8000 amazon/dynamodb-local

使用说明
-sharedDb 是否共享数据
-inMemory 写入内存而不写入文件
-optimizeDbBeforeStartup 同时需要指定-dbPath使得dynamoDB找到自己的文件


测试本地dynamoDB(需要安装aws-cli)

aws dynamodb list-tables --endpoint-url http://localhost:8000

运行本地dynamoDB每条命令都需要加上–endpoint-url
(竟然不能在configure中设置环境……)

Working with DynamoDB

working with table

Auto scaling

使用console创建table时,会默认开启auto scaling
对应权限控制以及角色策略
application-autoscaling对应权限名称
DynamoDBFullAccess策略中包含这个权限

working with item

Return Values

  • UpdateItem
    ALL_OLD 返回所有更新前的数据
    ALL_NEW 返回所有更新后的数据
    UPDATED_OLD 返回更新前的数据
    UPDATED_NEW 返回更新后的数据
  • PutItem/DeleteItem
    ALL_OLD

Using Expressions

nested attribute

[n] — for list elements
. (dot) — for map elements

Projection Expressions

获取指定的attributes而不是全部

Expression Attribute Names/Values

expression attribute name需要以#开头,用于表达式变量的替换。
以下几种情况需要使用expression attribute name

  • 与dynamoDB保留字冲突
  • 包含点名称的属性(例:Safety.Warning)
    .在表达式中作为attribute的引用,与变量名发生冲突
  • Expression Attribute Names里面访问nested attributes,处理如下:
    (在name里面,.被当作时字符)
    –projection-expression “#pr.#1star”
    –expression-attribute-names ‘{"#pr":“ProductReviews”, “#1star”:“OneStar”}’

expression attribute value需要以:开头,用于表达式值的替换。

Condition Expressions
  • attribute_not_exists
    传入primary key防止覆盖现有的item
    传入attribute可以检查是否存在对应的attribute
  • attribute_exists
    类似上面的用法

比较运算符的用法参考

Update Expressions
update-expression ::=
    [ SET action [, action] ... ]
    [ REMOVE action [, action] ...]
    [ ADD action [, action] ... ]
    [ DELETE action [, action] ...]

具体参考Update Expressions

Expiring Items with Time to Live

可以定义item的expire过期时间

  • TTL attributes must use the Number data type, and values must use the Unix epoch time format.
  • Items with no TTL attribute, or with an expiration time more than 5 years in the past, are not deleted.

On-Demand Backup and Restore

使用console或CLI备份,还原或删除备份
具体参考On-Demand Backup and Restore

Point-in-Time Recovery

提供实时备份功能
可以选择日期和时间来还原表 (day:hour:minute:second)
配置也会还原到之前时间下的配置

DynamoDB Transactions

  • TransactWriteItems
    最多操作25个item,最大支持4MB。
    和BatchWriteItem不同,BatchWriteItem里面有的会成功有的会失败
    不能对同一个item同时进行多个操作
    事务更新后备份时间段可能只有部分修改
    Idempotency保证了多次提交与第一次提交结果相同,需要client token支持,有效期为10分钟,10分钟后视为新的请求
  • TransactGetItems
    与TransactWriteItems类似,如果找不到其中的item将不返回任何数据
  • SERIALIZABLE
    SERIALIZABLE保证了并发操作结果相同
  • READ-COMMITTED
    READ-COMMITTED可确保读取操作始终为项目返回提交的值。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值