DynamoDB CLI written in Rust.
dynein /daɪ.nɪn/ is a command line interface for Amazon DynamoDB written in Rust. dynein is designed to make it simple to interact with DynamoDB tables/items from terminal.
dy get abc{"id": 123} ) over DynamoDB JSON ( {"id": {"N": "123"}} ).You can download binaries of a specific version from the releases page. For example, below instructions are example comamnds to download the latest version in each platform.
$ curl -O -L https://github.com/awslabs/dynein/releases/latest/download/dynein-macos.tar.gz
$ tar xzvf dynein-macos.tar.gz
$ mv dy /usr/local/bin/
$ dy --help$ curl -O -L https://github.com/awslabs/dynein/releases/latest/download/dynein-macos-arm.tar.gz
$ tar xzvf dynein-macos-arm.tar.gz
$ mv dy /usr/local/bin/
$ dy --help$ curl -O -L https://github.com/awslabs/dynein/releases/latest/download/dynein-linux.tar.gz
$ tar xzvf dynein-linux.tar.gz
$ sudo mv dy /usr/local/bin/
$ dy --help$ brew install dyneindynein is written in Rust, so you can build and install dynein with Cargo. To build dynein from source code you need to install Rust as a prerequisite.
$ git clone [[this_git_repository_url]]
$ cd dynein
$ cargo install --locked --path .
$ ./target/release/dy --helpYou can move the binary file named "dy" to anywhere under your $PATH.
First of all, please make sure you've already configured AWS Credentials in your environment. dynein depends on aws-sdk-rust - for example ~/.aws/credentials file, IAM EC2 Instance Profile, or environment variables such as AWS_DEFAULT_REGION / AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY / AWS_PROFILE.
One convenient way to check if your AWS credential configuration is ok to use dynein is to install and try to execute AWS CLI in your environment (e.g. $ aws dynamodb list-tables). Once you've configured AWS CLI, you should be ready to use dynein.
After you installed dynein you should have a binary named dy in your $PATH. The first command you can try is dy ls, which lists tables you have:
$ dy ls --all-regions
DynamoDB tables in region: us-west-2
EventData
EventUsers
* Forum
Thread
DynamoDB tables in region: us-west-1
No table in this region.
DynamoDB tables in region: us-east-2
UserBooks
Users
...Here --all-regions option enables you to iterate over all AWS regions and list all tables for you.
Next you can try dy scan with region and table options. dy scan command executes Scan API internally to retrieve all items in the table.
$ dy scan --region us-west-2 --table Forum
Name attributes
Amazon S3 {"Category":"Amazon Web Services"}
Amazon DynamoDB {"Views":1000,"Threads":2,"Messages":4,"Category":...Here Name is a primary key of this Forum table and attributes column contains rest attributes of each item.
You don't want to pass --region and --table everytime? Let's mark the table as "currently using" with the command dy use.
$ dy use Forum --region us-west-2Now you can interact with the table without specifying a target.
$ dy scan
Name attributes
Amazon S3 {"Category":"Amazon Web Services"}
Amazon DynamoDB {"Threads":2,"Views":1000,"Messages":4,"Category":...To find more features, dy help will show you complete list of available commands.
…dynein consists of multiple layers of subcommands. For example, dy admin and dy config require you to give additional action to run.
$ dy admin --help
dy-admin x.x.x
Admin operations such as creating/updating table or GSI
USAGE:
dy admin [OPTIONS]
FLAGS: ...
OPTIONS: ...
SUBCOMMANDS:
create Create new DynamoDB table or GSI. [API: CreateTable, UpdateTable]
delete Delete a DynamoDB table or GSI. [API: DeleteTable]
desc Show detailed information of a table. [API: DescribeTable]
help Prints this message or the help of the given subcommand(s)
list List tables in the region. [API: ListTables]
update Update a DynamoDB table. [API: UpdateTable etc]By executing following command, you can create a DynamoDB table.
$ dy admin create table mytable --keys pk,SThe easiest way to get familiar with dynein and DynamoDB would be executing dy bootstrap. The bootstrap subcommand creates sample tables and automatically load sample data defined here. After that, you'll see some sample commands to demonstrate basic usage of dynein.
…If you're interested in other available sample tables with data, check dy bootstrap --list and pass desired target to --sample option.
Using dynein, you can create a table:
$ dy admin create table app_users --keys app_id,S user_id,S
---
name: app_users
region: us-east-1
status: CREATING
schema:
pk: app_id (S)
sk: user_id (S)
mode: OnDemand
capacity: ~
gsi: ~
lsi: ~
stream: ~
count: 0
size_bytes: 0
created_at: "2020-03-03T13:34:43+00:00"After the table get ready (i.e. status: CREATING changed to ACTIVE), you can write-to and read-from the table.
$ dy use app_users
$ dy desc
---
name: app_users
region: us-east-1
status: ACTIVE
schema:
pk: app_id (S)
sk: user_id (S)
mode: OnDemand
capacity: ~
gsi: ~
lsi: ~
stream: ~
count: 0
size_bytes: 0
created_at: "2020-03-03T13:34:43+00:00"
$ dy put myapp 1234 --item '{"rank": 99}'
Successfully put an item to the table 'app_users'.
$ dy scan
app_id user_id attributes
myapp 1234 {"rank":99}Similarly you can update tables with dynein.
$ dy admin update table app_users --mode provisioned --wcu 10 --rcu 25NOTE: currently this feature is under development
Infrastracture as Code is a concept that you define code to provision "infrastructures", such as DynamoDB tables, with "declarative" way (On the other hand you can say dy admin create table and dy admin update table commands are "imperative" way).
To manage DynamoDB tables with "declarative" way, dynein provides dy admin plan and dy admin apply commands. Internally dynein executes AWS CloudFormation APIs to provision DynamoDB resources for you.
$ ls
mytable.cfn.yml
$ cat mytable.cfn.yml
Resources:
MyDDB:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: pk
AttributeType: S
KeySchema:
- AttributeName: pk
KeyType: HASH
BillingMode: PAY_PER_REQUEST
(currently not available) $ dy admin plan
(currently not available) $ dy admin applyCloudFormation manages DynamoDB tables through the resource type named AWS::DynamoDB::Table - visit the link for more information.
dy use and dy config to switch/manage contextBasically it's pretty straight forward to specify table with which you want to interact with: --table or -t option. Let's say you want to scan data in the customers table.
$ dy scan --table customers
... display items in the "customers" table ...However, dynein assume that tipically you're interested in only one table at some point. It means that passing table name for every single command execution is a kinf of waste of your time.
By using dy use for a table, you can call commands such as scan, get, query, and put without specifying table name.
$ dy use customers
$ dy scan
... display items in the "customers" table ...In detail, when you execute dy use command, dynein saves your table usage information in ~/.dynein/config.yml and caches table schema in ~/.dynein/cache.yml. You can dump them with dy config dump command.
$ ls ~/.dynein/
cache.yml config.yml
$ dy config dump
---
tables:
ap-northeast-1/customers:
region: ap-northeast-1
name: customers
pk:
name: user_id
kind: S
sk: ~
indexes: ~
---
using_region: ap-northeast-1
using_table: customersTo clear current table configuration, simply execute dy config clear.
$ dy config clear
$ dy config dump
---
tables: ~
---
using_region: ~
using_table: ~As an example let's assume you have official "Movie" sample data. To prepare the table with data loaded, simply you can execute dy bootstrap --sample movie.
$ dy bootstrap --No open issues yet, or sync has not completed.