diff --git a/.github/actions/ssm-send-command/action.yml b/.github/actions/ssm-send-command/action.yml index d38c0eec..dcc1dc26 100644 --- a/.github/actions/ssm-send-command/action.yml +++ b/.github/actions/ssm-send-command/action.yml @@ -17,13 +17,42 @@ runs: id: run-command run: | COMMAND_ID=$(aws ssm send-command \ - --instance-ids ${{ inputs.instance_id }} \ + --instance-ids ${{ inputs.instance-id }} \ --document-name "AWS-RunShellScript" \ - --parameters '{"commands": ["ls -l"]}' \ + --parameters '{"commands":["ls -l"]}' \ --output text \ --query "Command.CommandId") echo "command-id=$COMMAND_ID" >> $GITHUB_OUTPUT + - name: Check stop services command status and retrieve output + shell: bash + run: | + while true; do + STATUS=$(aws ssm list-command-invocations \ + --command-id ${{ steps.run-command.outputs.command-id }} \ + --details \ + --query "CommandInvocations[0].Status" \ + --output text) + echo "Command Status: $STATUS" + + OUTPUT=$(aws ssm list-command-invocations \ + --command-id ${{ steps.run-command.outputs.command-id }} \ + --details \ + --query "CommandInvocations[0].CommandPlugins[0].Output" \ + --output text) + echo "Command Output: $OUTPUT" + + if [ "$STATUS" == "Success" ]; then + echo "Command completed successfully." + break + elif [ "$STATUS" == "Failed" ] || [ "$STATUS" == "Cancelled" ]; then + echo "Command failed with status: $STATUS" + exit 1 + else + sleep 10 # Wait for 30 seconds before checking again + fi + done + - name: Wait for command completion shell: bash id: poll-status @@ -37,6 +66,8 @@ runs: --query "CommandInvocations[0].Status" \ --output text) + echo "status is $STATUS" + # Print a progress `.` token until the command completes. case $STATUS in Pending | InProgress | Delayed )