aws cliでのコマンドは非同期のため、以下のようなコマンドを連続で実行しようとすると怒られます。
aws elasticbeanstalk update-environment --environment-name $PROD_ENV --template-name production
aws elasticbeanstalk swap-environment-cnames --source-environment-name $PROD_ENV --destination-environment-name $STAGE_ENV
A client error (InvalidParameterValue) occurred when calling the SwapEnvironmentCNAMEs operation: Environment 'tekitouna-env-name' is pending deployment. Wait until the environment is available and try again.
なので待つようにしました。
npm install -g underscore-cli
while [ "Green" != $(aws elasticbeanstalk describe-environments --application-name $APP_NAME --environment-names $PROD_ENV | underscore select '.Environments .Health' --outfmt text) ]
do
echo "hoge"
sleep 5s
done
echo 'owatta'