Created
September 10, 2016 07:46
-
-
Save lalyos/9bf575f51d743d9b29211c26f2132bf8 to your computer and use it in GitHub Desktop.
Aws ssm command execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eo pipefail | |
if [[ "$TRACE" ]]; then | |
: ${START_TIME:=$(date +%s)} | |
export START_TIME | |
export PS4='+ [TRACE $BASH_SOURCE:$LINENO][ellapsed: $(( $(date +%s) - $START_TIME ))] ' | |
set -x | |
fi | |
debug() { | |
[[ "$DEBUG" ]] && echo "-----> $*" 1>&2 | |
} | |
aws-ssm() { | |
instanceId=$(aws ssm describe-instance-information --query InstanceInformationList[0].InstanceId --out text) | |
debug "type your command in multi-line, end with <CTRL-d>" | |
local commands=$(while read line; do echo -n "${line},"; done) | |
commandId=$( | |
aws ssm send-command \ | |
--output-s3-bucket-name seq-ssm \ | |
--document-name AWS-RunShellScript \ | |
--instance-ids $instanceId \ | |
--parameters "commands=${commands}echo DONE" \ | |
--query Command.CommandId --out text | |
) | |
debug "commandId=$commandId" | |
debug "OUTPUT" | |
aws s3 cp --only-show-errors s3://seq-ssm/$commandId/$instanceId/awsrunShellScript/0.aws:runShellScript/stdout . && cat stdout | |
} | |
main() { | |
: ${DEBUG:=1} | |
aws-ssm | |
} | |
[[ "$0" == "$BASH_SOURCE" ]] && main "$@" || true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment