Appreciate, respect and accept it, don't take it for granted

AWS Parameter Store to Bash Associative Arrays

2021-08-27

Parameter Store可以透過prefix的方式(get-parameters-by-path)取得多個值, 想要在bash進一步使用的話可以先轉換成Associative Arrays

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
# sample
# [
# {
# "Name": "/alpha/test/a",
# "Value": "a-data"
# },
# {
# "Name": "/alpha/test/b",
# "Value": "b-data"
# }
# ]
sample=$(aws ssm get-parameters-by-path --path /alpha/test --with-decryption --query "Parameters[*].{Name:Name,Value:Value}")

echo "${sample}" | jq -c '.[]'

declare -A test

for row in $(echo "${sample}" | jq -r '.[] | @base64'); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
# echo $(_jq '.Name')
# echo $(_jq '.Value')
test[$(_jq '.Name')]=$(_jq '.Value')
done

echo ${test[/alpha/test/a]}
echo ${test[/alpha/test/b]}

參考


Blog comments powered by Disqus