百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

dynein

> 数据库
开源

DynamoDB CLI 使用 Rust 编写。

397 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

DynamoDB CLI 使用 Rust 编写。

dynein - DynamoDB CLI

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.

  • Why use dynein?
    • Less Typing
    • Quick Start
    • For day-to-day tasks
  • Installation
    • Method 1. Download binaries
    • Method 2. Homebrew (MacOS)
    • Method 3. Building from source
  • How to Use
    • Prerequisites - AWS Credentials
    • Commands overview
    • Bootstrapping sample DynamoDB tables
    • Working with DynamoDB tables
      • Infrastracture as Code - enpowered by CloudFormation
      • dy use and dy config to switch/manage context
    • Working with DynamoDB items
      • Read
        • dy scan
        • dy get
        • dy query
      • Write
        • dy put
        • dy upd
        • dy del
    • Working with Indexes
    • Import/Export for DynamoDB items
      • dy export
      • dy import
    • Using DynamoDB Local with --region local option
  • Contribution
  • Misc
    • Asides
    • Troubleshooting
    • Ideas for future works

Why use dynein?

Less Typing

  • Auto completion for table/keyDefinitions enables using DynamoDB with minimum arguments. e.g. to get an item: dy get abc
  • Switching table context by RDBMS-ish "use".
  • Prefer standard JSON ( {"id": 123} ) over DynamoDB JSON ( {"id": {"N": "123"}} ).

Quick Start

  • Bootstrap command enables you to launch sample table with sample data sets.
  • Supports DynamoDB Local and you can test DyanmoDB at no charge.

For day-to-day tasks

  • Import/Export by single command: export DynamoDB items to CSV/JSON files and conversely, import them into tables.
  • Taking on-demand backup and restore data from them.

Installation

Method 1. Download binaries

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.

macOS

$ 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

macOS (ARM 64)

$ 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

Linux (x86-64)

$ 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

Method 2. Homebrew (macOS/Linux)

$ brew install dynein

Method 3. Building from source

dynein 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 --help

You can move the binary file named "dy" to anywhere under your $PATH.

How to Use

Prerequisites - AWS Credentials

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.

Commands overview

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-2

Now 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,S

Bootstrapping sample DynamoDB tables

The 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.

Working with DynamoDB tables

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 25

Infrastracture as Code - enpowered by CloudFormation

NOTE: 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 apply

CloudFormation 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 context

Basically 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: customers

To clear current table configuration, simply execute dy config clear.

$ dy config clear
$ dy config dump
---
tables: ~
---
using_region: ~
using_table: ~

Working with DynamoDB items

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 --

Issues· 33 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustawsbackupclicommand-line

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库