@@ -34,6 +34,7 @@ UsageString="
3434 [-m ec2|onPremise|onPrem|auto]
3535 [-c default|all|ssm:<parameter-store-name>|file:<file-path>]
3636 [-s]
37+ [-d]
3738 [-l INFO|DEBUG|WARN|ERROR|OFF]
3839
3940 e.g.
@@ -43,6 +44,8 @@ UsageString="
4344 amazon-cloudwatch-agent-ctl -a append-config -m onPremise -c file:/tmp/config.json -s
4445 3. query agent status:
4546 amazon-cloudwatch-agent-ctl -a status
47+ 4. apply a SSM parameter store config with dual-stack endpoints:
48+ amazon-cloudwatch-agent-ctl -d -a fetch-config -m ec2 -c ssm:AmazonCloudWatch-Config.json -s
4649
4750 -a: action
4851 stop: stop the agent process.
@@ -67,6 +70,9 @@ UsageString="
6770 -s: optionally restart after configuring the agent configuration
6871 this parameter is used for 'fetch-config', 'append-config', 'remove-config' action only.
6972
73+ -d: enable dual-stack endpoints for AWS API calls during config download
74+ this parameter is used for 'fetch-config', 'append-config', 'remove-config' actions only.
75+
7076 -l: log level to set the agent to INFO, DEBUG, WARN, ERROR, or OFF
7177 this parameter is used for 'set-log-level' only.
7278
@@ -91,7 +97,7 @@ agent_start() {
9197
9298 if [ " ${agent_name} " = " ${CWA_NAME} " ] && [ ! -f " ${TOML} " ]; then
9399 echo " ${CWA_NAME} is not configured. Applying amazon-cloudwatch-agent default configuration."
94- cwa_config ' default' ' false' " ${mode} " ' default'
100+ cwa_config ' default' ' false' " ${mode} " ' default' ' false '
95101 fi
96102
97103 if [ " ${SYSTEMD} " = ' true' ]; then
@@ -236,6 +242,7 @@ config_all() {
236242 restart=" ${2:- } "
237243 mode=" ${3:- } "
238244 multi_config=" ${4:- } "
245+ use_dualstack=" ${5:- } "
239246
240247 if [ -z " ${cwa_config_location} " ]; then
241248 cwa_config_location=' default'
@@ -245,7 +252,7 @@ config_all() {
245252
246253 if [ -n " ${cwa_config_location} " ]; then
247254 echo " ****** processing amazon-cloudwatch-agent ******"
248- cwa_config " ${cwa_config_location} " " ${restart} " " ${mode} " " ${multi_config} "
255+ cwa_config " ${cwa_config_location} " " ${restart} " " ${mode} " " ${multi_config} " " ${use_dualstack} "
249256 fi
250257}
251258
@@ -254,6 +261,7 @@ cwa_config() {
254261 restart=" ${2:- } "
255262 param_mode=" ${3:- } "
256263 multi_config=" ${4:- } "
264+ use_dualstack=" ${5:- } "
257265
258266 if [ " ${cwa_config_location} " = " ${ALL_CONFIG} " ] && [ " ${multi_config} " != ' remove' ]; then
259267 echo " ignore cwa configuration \" ${ALL_CONFIG} \" as it is only supported by action \" remove-config\" "
@@ -263,8 +271,12 @@ cwa_config() {
263271 if [ " ${cwa_config_location} " = " ${ALL_CONFIG} " ]; then
264272 rm -rf " ${JSON_DIR} " /*
265273 else
266- runDownloaderCommand=$( " ${CMDDIR} /config-downloader" --output-dir " ${JSON_DIR} " --download-source " ${cwa_config_location} " --mode ${param_mode} --config " ${COMMON_CONIG} " --multi-config ${multi_config} )
267- echo ${runDownloaderCommand} || return
274+ downloader_cmd=" ${CMDDIR} /config-downloader --output-dir ${JSON_DIR} --download-source ${cwa_config_location} --mode ${param_mode} --config ${COMMON_CONIG} --multi-config ${multi_config} "
275+ if [ " ${use_dualstack} " = ' true' ]; then
276+ downloader_cmd=" ${downloader_cmd} -d"
277+ fi
278+ runDownloaderCommand=$( ${downloader_cmd} )
279+ echo " ${runDownloaderCommand} " || return
268280 fi
269281
270282 if [ ! " $( ls ${JSON_DIR} ) " ]; then
@@ -354,6 +366,7 @@ main() {
354366 cwa_config_location=' '
355367 restart=' false'
356368 mode=' ec2'
369+ use_dualstack=' false'
357370
358371 # detect which init system is in use
359372 if [ " $( /sbin/init --version 2> /dev/null | grep -c upstart) " = 1 ]; then
@@ -369,7 +382,7 @@ main() {
369382 fi
370383
371384 OPTIND=1
372- while getopts " :hsa:c:m:l:" opt; do
385+ while getopts " :hsa:c:m:l:d " opt; do
373386 case " ${opt} " in
374387 h)
375388 echo " ${UsageString} "
@@ -380,6 +393,7 @@ main() {
380393 c) cwa_config_location=" ${OPTARG} " ;;
381394 m) mode=" ${OPTARG} " ;;
382395 l) log_level=" ${OPTARG} " ;;
396+ d) use_dualstack=' true' ;;
383397 \? )
384398 echo " Invalid option: -${OPTARG} ${UsageString} " >&2
385399 ;;
@@ -405,9 +419,9 @@ main() {
405419 case " ${action} " in
406420 stop) stop_all ;;
407421 start) start_all " ${mode} " ;;
408- fetch-config) config_all " ${cwa_config_location} " " ${restart} " " ${mode} " ' default' ;;
409- append-config) config_all " ${cwa_config_location} " " ${restart} " " ${mode} " ' append' ;;
410- remove-config) config_all " ${cwa_config_location} " " ${restart} " " ${mode} " ' remove' ;;
422+ fetch-config) config_all " ${cwa_config_location} " " ${restart} " " ${mode} " ' default' " ${use_dualstack} " ;;
423+ append-config) config_all " ${cwa_config_location} " " ${restart} " " ${mode} " ' append' " ${use_dualstack} " ;;
424+ remove-config) config_all " ${cwa_config_location} " " ${restart} " " ${mode} " ' remove' " ${use_dualstack} " ;;
411425 status) status_all ;;
412426 # helpers for ssm package scripts to workaround fact that it can't determine if invocation is due to
413427 # upgrade or install
0 commit comments