cmdline-dynamo 0.0.2
Python command line interface for copying/restoring DynamoDB tables and items.

# Copy DynamoDB data CLI
>  Command-line interface to copy Dynamodb data across environments.
> See [DynamoDB Catalog](https://ecoation.atlassian.net/l/c/YaYKvSXH) for information on how to query specific items.
#### Author: Simon Ryu


### Pre-requisite

- QA_COPY access key ids and secret access keys are set for environments you want to copy from & to
- Profiles in `.aws/credentials` are configured for desired environments as following profile names: 'test', 'dev', 'stage' and 'prod'
- Install `cmdline-dynamo` package: ```pip install cmdline-dynamo```

## Running the CLI

#### Help message
> Displays a help message for using the CLI, also run `$ dynamo copy -h` and `$ dynamo restore -h` for help messages with copy and restore commands.


`$ dynamo -h`
```
Command line interface to copy/restore DynamoDB tables and items

positional arguments:
  {copy,restore}
    copy          Copy table or items from source to target envrionment
    restore       Restore table from on-demand backup, or items from s3 export. To restore a table, a back-up table named {table_name}-backup must
                  exist beforehand (e.g. b-c-product-backup).

optional arguments:
  -h, --help      show this help message and exit
```

#### Copy table
> Creates an on-demand target table backup, truncates all items in the target table and copies all source table items in its place.


```$ dynamo copy --table b-c-config --source prod --target dev```


Copy `b-c-config` table from production to dev environment.


#### Copy items
> Copies queried items from source table to target table. Queries items in source and target table, exports target items to S3, deletes them from the target table, then copies queried source items to the target table.
> For querying with sort keys, the comparision condition is begins_with.


```
$ dynamo copy --table b-c-product --pk customer#{customer_id} --sk F#{farm_id}#P#{phase_id}# --source dev --target test
```

Copy all rows of a phase of a customer's farm from dev to test environment.


```$ dynamo copy --table b-c-product --pk recipe --index entities-index --source prod --target stage```


Copy recipe items in `b-c-product` from production to stage environment. `recipe` is the name of the `etype`, which is the name of the partition key of a secondary index named `entities-index`.


#### Restore table
> Truncates the original table, and copies the back up table to the original table. The backup table is then deleted.


```$ dynamo restore --table b-c-config --env test```


Restore `b-c-config` in test environment. A back-up table named `b-c-config-backup` must be created from an on-demand backup first. This command truncates all items in `b-c-config`, copies all items from `b-c-config-backup`, and deletes the `b-c-config-backup` table.


#### Restore items
> Reads exported csv file from QA S3 bucket and writes the items to the table.


```$ dynamo restore --table b-c-product --pk config-set --env dev```


Restore `config-set` items in dev environment. An s3 file with key `dynamodb_export/b-c-product/{b-c-product_config-set.csv` must exist in `eis-qa-testing-dev` bucket in order to run this command.