Command Line Interface for Dynamo DB
Content:
The easiest way to install dyn-cli is to use pip:
$ pip install dyn-cli
Synopsis:
$ dyn [OPTIONS] COMMAND [ARGS]...
List of commands:
You can configure your AWS credentials via options. The following table shows these options.
Option | Description |
---|---|
-a , --access-key AWS_ACCESS_KEY |
AWS Access Key ID. (default: local) |
-s , --secret-key AWS_SECRET_KEY |
AWS Secret Key. (default: local) |
-r , --region AWS_REGION |
AWS Region. (default: us-east-1) |
-n , --no-local |
Disable local endpoint_url set up to http://localhost:8000. (default: false) |
-h , --help |
Show help message. |
List all tables of DynamoDB.
$ dyn list_tables
Creates a DynamoDB table with TABLE
name and attributes defined in ATTRIBUTE
.
$ dyn create_table [OPTIONS] TABLE ATTRIBUTE [ATTRIBUTE]...
Option | Description |
---|---|
-r , --read-units INTEGER |
Read capacity units. (default: 1) |
-w , --write-units INTEGER |
Write capacity units. (default: 1) |
The ATTRIBUTE
argument can be defined like: name:type[:pk][:sk]
- name - name of attribute.
- type - type of attribute that can be:
s
- stringn
- numberb
- binary
pk
- first attribute of primary key (partition key - HASH)sk
- second attribute of primary key (sort key - RANGE)
Modifies a DynamoDB table with TABLE name.
$ dyn update_table [OPTIONS] TABLE
Option | Description |
---|---|
-r , --read-units INTEGER |
Read capacity units. (default: 1) |
-w , --write-units INTEGER |
Write capacity units. (default: 1) |
Deletes a table of DynamoDB.
$ dyn delete_table TABLE
Listing all tables:
$ dyn list_tables
{
"TableNames": [
"Movies",
"Music"
]
}
Creating Music table:
$ dyn create_table Music Artist:s:pk SongTitle:s:sk
{
"TableDescription": {
"AttributeDefinitions": [
{
"AttributeName": "Artist",
"AttributeType": "S"
},
{
"AttributeName": "SongTitle",
"AttributeType": "S"
}
],
"CreationDateTime": "2017-07-02T23:19:52.932000-03:00",
"ItemCount": 0,
"KeySchema": [
{
"AttributeName": "Artist",
"KeyType": "HASH"
},
{
"AttributeName": "SongTitle",
"KeyType": "RANGE"
}
],
"ProvisionedThroughput": {
"LastDecreaseDateTime": "1969-12-31T21:00:00-03:00",
"LastIncreaseDateTime": "1969-12-31T21:00:00-03:00",
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
},
"TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/Music",
"TableName": "Music",
"TableSizeBytes": 0,
"TableStatus": "ACTIVE"
}
}
Updating Music table:
$ dyn update_table Music -r 10 -w 10
{
"TableDescription": {
"AttributeDefinitions": [
{
"AttributeName": "Artist",
"AttributeType": "S"
},
{
"AttributeName": "SongTitle",
"AttributeType": "S"
}
],
"CreationDateTime": "2017-07-02T23:19:52.932000-03:00",
"ItemCount": 0,
"KeySchema": [
{
"AttributeName": "Artist",
"KeyType": "HASH"
},
{
"AttributeName": "SongTitle",
"KeyType": "RANGE"
}
],
"ProvisionedThroughput": {
"LastDecreaseDateTime": "1969-12-31T21:00:00-03:00",
"LastIncreaseDateTime": "1969-12-31T21:00:00-03:00",
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 10,
"WriteCapacityUnits": 10
},
"TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/Music",
"TableName": "Music",
"TableSizeBytes": 0,
"TableStatus": "ACTIVE"
}
}
Deleting Music table:
$ dyn delete_table Music
{
"TableDescription": {
"ItemCount": 0,
"ProvisionedThroughput": {
"LastDecreaseDateTime": "1969-12-31T21:00:00-03:00",
"LastIncreaseDateTime": "1969-12-31T21:00:00-03:00",
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 10,
"WriteCapacityUnits": 10
},
"TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/Music",
"TableName": "Music",
"TableSizeBytes": 0,
"TableStatus": "DELETING"
}
}