@@ -7,48 +7,31 @@ fetch_ssm_parameters() {
7
7
local output_file=" $2 "
8
8
9
9
# check if the ssm_path is set
10
- if [ -z " $ssm_path " ]; then
10
+ if [[ -z " ${ ssm_path} " ] ]; then
11
11
echo " ssm_path is not set"
12
12
return 1
13
13
fi
14
14
15
15
# check if the output_file is set
16
- if [ -z " $output_file " ]; then
16
+ if [[ -z " ${ output_file} " ] ]; then
17
17
echo " output_file is not set"
18
18
return 1
19
19
fi
20
20
21
21
# trim off ssm: prefix
22
- ssm_path=${ssm_path// ssm:/ }
22
+ ssm_path=" ${ssm_path// ssm:/ } "
23
23
24
- # Get all SSM parameter names under the given path
25
24
#
26
25
# NOTE: The maximum number of parameters that can be retrieved is 25 to avoid throttling
27
26
# in the case of misconfigured SSM path with a large number of child parameters
28
- local ssm_parameter_names
29
- ssm_parameter_names=$( aws ssm get-parameters-by-path \
30
- --path " $ssm_path " \
27
+ aws ssm get-parameters-by-path \
28
+ --path " ${ssm_path} " \
31
29
--recursive \
32
30
--max-items 25 \
33
31
--with-decryption \
34
- --query ' Parameters[].Name' \
35
- --output text)
36
-
37
- # Loop through each parameter and export it as an environment variable
38
- for name in $ssm_parameter_names ; do
39
- local value
40
- value=$( aws ssm get-parameter \
41
- --name " $name " \
42
- --with-decryption \
43
- --query ' Parameter.Value' \
44
- --output text)
45
- if [ -n " $name " ] && [ -n " $value " ]; then
46
- local var_name
47
- var_name=$( echo " $name " | awk -F/ ' {print toupper($NF)}' )
48
- echo " Exported variable: $var_name "
49
- echo " $var_name =$value " >> " $output_file "
50
- fi
51
- done
32
+ --query ' Parameters[*].{Name: Name, Value: Value}' --output json \
33
+ | jq -r ' .[] | [(.Name | split("/")[-1] | ascii_upcase), (["\"", .Value, "\""] | join(""))] | join("=")' \
34
+ > " ${output_file} "
52
35
}
53
36
54
37
FROM=" $1 "
@@ -59,7 +42,7 @@ s3://*)
59
42
exec aws s3 cp " $FROM " " $TO "
60
43
;;
61
44
ssm:* )
62
- fetch_ssm_parameters " $FROM " " $TO "
45
+ fetch_ssm_parameters " ${ FROM} " " ${TO} "
63
46
;;
64
47
* )
65
48
exec curl -Lfs -o " $TO " " $FROM "
0 commit comments