Shell Script Create DynamoDB Tables

ShellScriptCreateDynamoDBTables

#howtorun

#dynamodb-scripts/create-device-dynamo-tables.sh{ENV}{WriteCapacityUnits}{ReadCapacityUnits}

#eg:dynamodb-scripts/create-device-dynamo-tables.shint55

echo"StarttocreatetheDynamoDbtable"

awsdynamodbcreate-table--table-namesillycat_device-$1-devicePairingInfo\

--key-schemaAttributeName=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-definitionsAttributeName=serialNumber,AttributeType=SAttributeName=groupUUID,AttributeType=SAttributeName=pairingToken,AttributeType=SAttributeName=deviceUUID,AttributeType=S\

--provisioned-throughputWriteCapacityUnits=$2,ReadCapacityUnits=$3

echo"WaitforthetablecreationfinishonAWS"

awsdynamodbwaittable-exists--table-namesillycat_device-$1-devicePairingInfo

echo"AddTTLcolumntothattable"

awsdynamodbupdate-time-to-live--table-namesillycat_device-$1-devicePairingInfo--time-to-live-specificationEnabled=true,AttributeName=pairingCodeDeleteTime

echo"Creationisdone.Enjoyit."

Thereareseveralimportantpartsinthisscript.

wait,wecanwaituntilthetableexistsintheAWS.Thatisveryuseful.

ttl,wecansetupttlforonecolumninthetable

GSI,wecancreateotherGSIinthistable.

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/

相关推荐