add a command to cloudformation wait any final state, and display events while waiting
- Dominant language
- Python
- Stars
- 17.3k
- Forks
- 4.6k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 13
Description
This is specially useful during automated deployments.
- wait until stack is in any final state:
- CREATE_FAILED
- DELETE_COMPLETE
- DELETE_FAILED
- ROLLBACK_COMPLETE
- ROLLBACK_FAILED
- UPDATE_COMPLETE
- UPDATE_ROLLBACK_COMPLETE
- UPDATE_ROLLBACK_FAILED
- log stack events emitted while waiting.
Currently I achieve this using the following script, but having this as part of the cli would be much more helpful:
```bash
cloudformation_tail() {
local stack="$1"
local region="$2"
local lastEvent
local lastEventId
local stackStatus=$(aws cloudformation describe-stacks --region $region --stack-name $stack | jq -c -r .Stacks[0].StackStatus)
until \
[ "$stackStatus" = "CREATE_COMPLETE" ] \
|| [ "$stackStatus" = "CREATE_FAILED" ] \
|| [ "$stackStatus" = "DELETE_COMPLETE" ] \
|| [ "$stackStatus" = "DELETE_FAILED" ] \
|| [ "$stackStatus" = "ROLLBACK_COMPLETE" ] \
|| [ "$stackStatus" = "ROLLBACK_FAILED" ] \
|| [ "$stackStatus" = "UPDATE_COMPLETE" ] \
|| [ "$stackStatus" = "UPDATE_ROLLBACK_COMPLETE" ] \
|| [ "$stackStatus" = "UPDATE_ROLLBACK_FAILED" ]; do
#[[ $stackStatus == *""* ]] || [[ $stackStatus == *"CREATE_FAILED"* ]] || [[ $stackStatus == *"COMPLETE"* ]]; do
lastEvent=$(aws cloudformation describe-stack-events --region $region --stack $stack --query 'StackEvents[].{ EventId: EventId, LogicalResourceId:LogicalResourceId, ResourceType:ResourceType, ResourceStatus:ResourceStatus, Timestamp: Timestamp }' --max-items 1 | jq .[0])
eventId=$(echo "$lastEvent" | jq -r .EventId)
if [ "$eventId" != "$lastEventId" ]
then
lastEventId=$eventId
echo $(echo $lastEvent | jq -r '.Timestamp + "\t-\t" + .ResourceType + "\t-\t" + .LogicalResourceId + "\t-\t" + .ResourceStatus')
fi
sleep 3
stackStatus=$(aws cloudformation describe-stacks --region $region --stack-name $stack | jq -c -r .Stacks[0].StackStatus)
done
echo "Stack Status: $stackStatus"
}
cloudformation_tail $SERVICE_STACK_NAME $REGION
```
which produces the following result on an update:
```
Awaiting completion...
2017-10-11T19:28:51.066Z - AWS::CloudFormation::Stack - my-stack-name - UPDATE_IN_PROGRESS
2017-10-11T19:28:57.591Z - AWS::ECS::TaskDefinition - TaskDefinition - UPDATE_IN_PROGRESS
2017-10-11T19:29:00.282Z - AWS::ECS::Service - Service - UPDATE_IN_PROGRESS
2017-10-11T19:36:05.919Z - AWS::CloudFormation::Stack - my-stack-name - UPDATE_COMPLETE_CLEANUP_IN_PROGRESS
Stack Status: UPDATE_COMPLETE
```
Contributor guide
Assessment
This issue has not been assessed yet.