-
Notifications
You must be signed in to change notification settings - Fork 7
/
export-data.sh
executable file
·43 lines (34 loc) · 1.03 KB
/
export-data.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
# usage: export-data-for-local-import.sh <TableName> [-r us-east-2] [-l]
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
USE_LOCAL=""
Region=""
TableName="$1"
shift
while getopts ":lr:" opt; do
case ${opt} in
l )
USE_LOCAL='--endpoint-url http://localhost:8000'
;;
r )
Region="--region $OPTARG"
;;
\?)
echo "Invalid option. -$OPTARG usage: export-data-for-local-import.sh <TableName> [-r us-east-2] [-l]" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
chkreqs() {
command -v jq > /dev/null
test $? -ne 0 && abort "jq required"
}
chkreqs
echo "RUNNING: aws dynamodb scan --table-name ${TableName} ${Region} ${USE_LOCAL}"
aws dynamodb scan --table-name ${TableName} ${Region} ${USE_LOCAL} \
| jq --arg TableName ${TableName} '{ ($TableName): [.Items[] | {PutRequest: {Item: .}}]}' > ${DIR}/data/${TableName}.json
test $? -eq 0 && echo "WROTE: ${DIR}/data/${TableName}.json"