Skip to content

Instantly share code, notes, and snippets.

@Jamie-BitFlight
Forked from lalyos/aws-ssm.sh
Created February 1, 2017 13:23
Show Gist options
  • Save Jamie-BitFlight/6c2fe1762c1a52b0f2b1b754eda0be7f to your computer and use it in GitHub Desktop.
Save Jamie-BitFlight/6c2fe1762c1a52b0f2b1b754eda0be7f to your computer and use it in GitHub Desktop.
Aws ssm command execution
#!/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