「EC2: コマンドを実行」アクションはバックエンドにAWS Systems Managerの Run Commandで「AWS-RunPowerShellScript」のドキュメントを使用しています。
この場合、スクリプトの最後で exit 命令を呼び出し、成功なら0、それ以外なら0以外を明示的に実行する必要があります。
PowerShell requires that you call
exitexplicitly in your scripts for Run Command to successfully capture the exit code.https://docs.aws.amazon.com/systems-manager/latest/userguide/run-command-handle-exit-status.html
例えば、以下のようなスクリプトを実行し、コマンド内の実行結果によって、 exit を実行します。
aws ec2 describe-instances --instance-ids i-09f749540b678518d
$exitCode = $LASTEXITCODE
if ($exitCode -ne 0) {
Write-Error "aws cli failed with exit code $exitCode"
exit 1
}
Write-Output "EC2 start-instances succeeded"
exit 0
関連
コマンドでの終了コードの使用 - AWS Systems Manager
https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/run-command-handle-exit-status.html