Shell Script Create DynamoDB Tables

Shell Script Create DynamoDB Tables

# how to run
# dynamodb-scripts/create-device-dynamo-tables.sh {ENV} {WriteCapacityUnits} {ReadCapacityUnits}
# eg: dynamodb-scripts/create-device-dynamo-tables.sh int 5 5
echo "Start to create the DynamoDb table"
aws dynamodb create-table --table-name sillycat_device-$1-devicePairingInfo \
--key-schema AttributeName=serialNumber,KeyType=HASH \
--global-secondary-indexes \
IndexName=groupUUID-index,KeySchema=["{AttributeName=groupUUID,KeyType=HASH}"],Projection={ProjectionType=ALL},ProvisionedThroughput="{WriteCapacityUnits=$2,ReadCapacityUnits=$3}" \
IndexName=pairingToken-index,KeySchema=["{AttributeName=pairingToken,KeyType=HASH}"],Projection={ProjectionType=ALL},ProvisionedThroughput="{WriteCapacityUnits=$2,ReadCapacityUnits=$3}" \
IndexName=deviceUUID-index,KeySchema=["{AttributeName=deviceUUID,KeyType=HASH}"],Projection={ProjectionType=ALL},ProvisionedThroughput="{WriteCapacityUnits=$2,ReadCapacityUnits=$3}" \
--attribute-definitions AttributeName=serialNumber,AttributeType=S AttributeName=groupUUID,AttributeType=S AttributeName=pairingToken,AttributeType=S AttributeName=deviceUUID,AttributeType=S \
--provisioned-throughput WriteCapacityUnits=$2,ReadCapacityUnits=$3

echo "Wait for the table creation finish on AWS"
aws dynamodb wait table-exists --table-name sillycat_device-$1-devicePairingInfo

echo "Add TTL column to that table"
aws dynamodb update-time-to-live --table-name sillycat_device-$1-devicePairingInfo --time-to-live-specification Enabled=true,AttributeName=pairingCodeDeleteTime

echo "Creation is done. Enjoy it."

There are several important parts in this script.
wait, we can wait until the table exists in the AWS. That is very useful.
ttl, we can set up ttl for one column in the table
GSI, we can create other GSI in this table.


References:
https://docs.aws.amazon.com/cli/latest/reference/dynamodb/update-time-to-live.html
https://docs.aws.amazon.com/cli/latest/reference/dynamodb/wait/index.html
https://docs.aws.amazon.com/cli/latest/reference/dynamodb/wait/table-exists.html
https://aws.amazon.com/cn/blogs/aws/new-manage-dynamodb-items-using-time-to-live-ttl/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值