Aws cli by example

November 26, 2018    aws cli

Dynamo DB

Get value using primary key

aws dynamodb get-item --table-name users --key '{"username": {"S": "test"}}'

Dump table data as csv

This expects that you have installed jq command on you system.

aws dynamodb scan --table-name users \
  --query "Items[].[username.S,email.S,passwordHash.S]" \
  --output json | jq -r '.[] | @csv' > dump.csv

Query using a portion of composite key

  aws dynamodb query --table-name users \
   --key-condition-expression "username = :username" \
   --expression-attribute-values  '{":username":{"S":"test user"}}'

KMS

Generate data key from KMS master key

aws kms generate-data-key-without-plaintext --key-id <<KMS master key>> --key-spec AES_256 --query CiphertextBlob --output text


comments powered by Disqus