Skip to content

A simple command line tool for CloudFront Key Value Store.

License

Notifications You must be signed in to change notification settings

michimani/cfkvs

Repository files navigation

cfkvs

This is a simple command line tool for CloudFront Key Value Store.

codecov

Features

  • KeyValueStore
    • list
    • create
    • info
    • sync
  • Item (Key-Value pair)
    • list
    • get
    • put
    • delete

Comparison with AWS CLI commands

AWS CLI cfkvs
cloudfront create-key-value-store cfkvs kvs create
cloudfront delete-key-value-store -
cloudfront describe-key-value-store -
cloudfront list-key-value-stores cfkvs kvs list
cloudfront update-key-value-store -
cloudfront-keyvaluestore delete-key cfkvs item delete
cloudfront-keyvaluestore describe-key-value-store -
cloudfront-keyvaluestore get-key cfkvs item get
cloudfront-keyvaluestore list-keys cfkvs item list
cloudfront-keyvaluestore put-key cfkvs item put
cloudfront-keyvaluestore update-keys -
- cfkvs kvs sync
- cfkvs kvs info

Installation

Homebrew

brew install michimani/tap/cfkvs

Usage

$ cfkvs -h

Usage: cfkvs <command> [flags]

A simple cli tool to manage CloudFront Key Value Stores.

Flags:
  -h, --help              Show context-sensitive help.
  -D, --debug             Enable debug mode.
      --output="table"    Output format. One of: json, table.
      --version           Print version information and quit

Commands:
  kvs list       List key value stores in your account.
  kvs create     Create a key value store.
  kvs info       Show information of the key value store.
  kvs sync       Sync items in the key value store with S3 object or specified JSON file.
  item list      List items in the key value store.
  item get       Get an item in the key value store.
  item put       Put an item in the key value store.
  item delete    Delete an item in the key value store.

Run cfkvs <command> --help for more information on a command.

Examples

Sync items in the key value store with S3 object

Assume that the following key-value pairs exist in the KeyValueStore cf-kvs-sample.

+-------+---------+
| KEY   | VALUE   |
+-------+---------+
| key-1 | value-1 |
| key-2 | value-2 |
| key-3 | value-3 |
+-------+---------+

Consider synchronizing this KeyValueStore with the data of the following S3 object named data.json.

{
  "data": [
    {"key": "key-1", "value": "v 1"},
    {"key": "key-2", "value": "value-2"},
    {"key": "key-4", "value": "v 4"}
  ]
}

You can check the changes in the KeyValueStore by synchronizing it with data.json using the following command.

$ cfkvs kvs sync \
--kvs-name='cf-kvs-sample' \
--bucket="${YOUR_BUCKET_NAME}" \
--key='data.json'
[ADDED] Following items will be added.
+---+-------+-------+
| # | KEY   | VALUE |
+---+-------+-------+
| 1 | key-4 | v 4   |
+---+-------+-------+

[UPDATED] Following items will be updated.
+---+-------+--------------+-------------+
| # | KEY   | BEFORE VALUE | AFTER VALUE |
+---+-------+--------------+-------------+
| 1 | key-1 | value-1      | v 1         |
+---+-------+--------------+-------------+

[DELETED] No items will be deleted.

If you want to delete keys that do not exist in data.json, add the --delete flag.

$ cfkvs kvs sync \
--name='cf-kvs-sample' \
--bucket="${YOUR_BUCKET_NAME}" \
--key='data.json' \
--delete
[ADDED] Following items will be added.
+---+-------+-------+
| # | KEY   | VALUE |
+---+-------+-------+
| 1 | key-4 | v 4   |
+---+-------+-------+

[UPDATED] Following items will be updated.
+---+-------+--------------+-------------+
| # | KEY   | BEFORE VALUE | AFTER VALUE |
+---+-------+--------------+-------------+
| 1 | key-1 | value-1      | v 1         |
+---+-------+--------------+-------------+

[DELETED] Following items will be deleted.
+---+-------+---------+
| # | KEY   | VALUE   |
+---+-------+---------+
| 1 | key-3 | value-3 |
+---+-------+---------+

If you add the --yes or -y flag, the synchronization will actually be executed.

$ cfkvs kvs sync \
--name='cf-kvs-sample' \
--bucket="${YOUR_BUCKET_NAME}" \
--key='data.json' \
--delete \
--yes

Sync items in the key value store with a JSON file

You can synchronize the key-value store with the JSON file specified by the --file flag in the same way as synchronizing with an S3 object.

If you specify the --file flag and --bucket and --key at the same time, the --file flag takes precedence.

$ cfkvs kvs sync \
--name='cf-kvs-sample' \
--file='./path/to/data.json'

Describe a key value store

The Describe action for CloudFront Key Value Store has two actions: CloudFront:DescribeKeyValueStore and CloudFrontKeyValueStore:DescribeKeyValueStore. The cfkvs kvs info command can get the merged information of these actions.

$ cfkvs kvs info --kvs-name='cf-kvs-sample' --output=json

Output:

{
    "id": "xxxxxxxx-0000-0000-0000-xxxxxxxxxxxx",
    "arn": "arn:aws:cloudfront::000000000000:key-value-store/xxxxxxxx-0000-0000-0000-xxxxxxxxxxxx",
    "name": "cf-kvs-sample",
    "comment": "sample kvs",
    "status": "READY",
    "itemCount": 2,
    "totalSizeInBytes": 8,
    "created": "2024-08-30T14:12:09.334Z",
    "lastModified": "2024-08-30T14:12:09.334Z",
    "failureReason": "",
    "eTag": "E3XXXXXXXXXXXX"
}

License

MIT

Author

michimani