CLI ve bir bulutlaştırma şablonu aracılığıyla bir AWS örneği oluşturmak için bir bash komut dosyası kullanıyorum. Komut dizimde hareket etmeden önce komutumun örnek oluşturma işlemi tamamlanana kadar beklemesini istiyorum. Şu anda, her 5 saniyede bir "açıklama yığınları" oluşturmak için bir while döngüsü kullanıyorum ve status = "CREATE_COMPLETE" veya bazı hata durumu olduğunda döngüden çıkıyorum. Bunu yapmanın daha şık bir yolu bilen var mı? EC2-bekle-örneği-varAWS örnek oluşturma işlemi tamamlanıncaya kadar bash komut dosyasında nasıl beklenir
stackStatus="CREATE_IN_PROGRESS"
while [[ 1 ]]; do
echo "${AWS_CLI_PATH}" cloudformation describe-stacks --region "${CfnStackRegion}" --stack-name "${CfnStackName}"
response=$("${AWS_CLI_PATH}" cloudformation describe-stacks --region "${CfnStackRegion}" --stack-name "${CfnStackName}" 2>&1)
responseOrig="$response"
response=$(echo "$response" | tr '\n' ' ' | tr -s " " | sed -e 's/^ *//' -e 's/ *$//')
if [[ "$response" != *"StackStatus"* ]]
then
echo "Error occurred creating AWS CloudFormation stack. Error:"
echo " $responseOrig"
exit -1
fi
stackStatus=$(echo $response | sed -e 's/^.*"StackStatus"[ ]*:[ ]*"//' -e 's/".*//')
echo " StackStatus: $stackStatus"
if [[ "$stackStatus" == "ROLLBACK_IN_PROGRESS" ]] || [[ "$stackStatus" == "ROLLBACK_COMPLETE" ]] || [[ "$stackStatus" == "DELETE_IN_PROGRESS" ]] || [[ "$stackStatus" == "DELETE_COMPLETE" ]]; then
echo "Error occurred creating AWS CloudFormation stack and returned status code ROLLBACK_IN_PROGRESS. Details:"
echo "$responseOrig"
exit -1
elif [[ "$stackStatus" == "CREATE_COMPLETE" ]]; then
break
fi
# Sleep for 5 seconds, if stack creation in progress
sleep 5
done
Hiçbir şey - Bir * sonra uzun kırmak isteyebilirsiniz * Yine de zaman. Daha zarif çözümler var, ama muhtemelen 'bash' – arco444
kapsamı dışında daha şık bir çözüm görmek isterim! (öncelikle spam aws api'den kaçınmak için ...) – Cyberwiz