Skip to content

Commit

Permalink
Handle failed commands
Browse files Browse the repository at this point in the history
  • Loading branch information
nonspecialist committed Dec 15, 2017
1 parent f4eab29 commit 3ab9439
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ssm-run
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ ID=$( aws ssm send-command \
--output text
)

echo "Command launched with id $ID"

# Wait for all instances to have finished running, one way or another
n_instances=$( echo $INSTANCE_IDS | wc -w )
while true; do
Expand All @@ -32,7 +34,12 @@ done

for instance in $INSTANCE_IDS; do
STATUS=$( aws ssm get-command-invocation --command-id $ID --instance-id $instance --query Status --output text )
RESULT=$( aws ssm get-command-invocation --command-id $ID --instance-id $instance --query StandardOutputContent --output text )
if [ "x$STATUS" = "xSuccess" ]; then
RESULT=$( aws ssm get-command-invocation --command-id $ID --instance-id $instance --query StandardOutputContent --output text )
else
RESULT=$( aws ssm get-command-invocation --command-id $ID --instance-id $instance --query StandardErrorContent --output text )
fi

echo "RESULTS FROM $instance (STATUS $STATUS):"
echo "$RESULT"
echo "------------------------------------"
Expand Down

0 comments on commit 3ab9439

Please sign in to comment.