Skip to content

Commit 460bbf9

Browse files
committed
Show resources/outputs after deploy, search for orphans on cleanup
- deploy.sh: shows all stack resources and outputs after create/update - deploy.sh: --no-fail-on-empty-changeset so re-running shows info - cleanup.sh: when stack is gone, searches for orphaned resources by tag (uses resourcegroupstaggingapi to find by tutorial tag or cfn stack tag)
1 parent 1671007 commit 460bbf9

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

cleanup.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,31 @@ STATUS=$(aws cloudformation describe-stacks --stack-name "$STACK_NAME" \
7373

7474
if [ "$STATUS" = "NONE" ] || [ "$STATUS" = "DELETE_COMPLETE" ]; then
7575
echo "Stack $STACK_NAME does not exist."
76+
echo ""
77+
echo "Searching for orphaned resources tagged with this stack name..."
78+
echo "(Resources that may have been left behind from a failed deletion)"
79+
echo ""
80+
# Search by tag
81+
aws resourcegroupstaggingapi get-resources \
82+
--tag-filters "Key=tutorial,Values=$STACK_NAME" \
83+
--query 'ResourceTagMappingList[].{ARN:ResourceARN}' --output table 2>/dev/null || true
84+
# Also search by name prefix
85+
aws resourcegroupstaggingapi get-resources \
86+
--tag-filters "Key=aws:cloudformation:stack-name,Values=$STACK_NAME" \
87+
--query 'ResourceTagMappingList[].{ARN:ResourceARN}' --output table 2>/dev/null || true
7688
exit 0
7789
fi
7890

7991
echo "Stack: $STACK_NAME (status: $STATUS)"
80-
echo "Resources:"
92+
echo ""
93+
echo "=== Stack Resources ==="
8194
aws cloudformation list-stack-resources --stack-name "$STACK_NAME" \
82-
--query 'StackResourceSummaries[].{Type:ResourceType,LogicalId:LogicalResourceId,Status:ResourceStatus}' --output table
95+
--query 'StackResourceSummaries[].{Type:ResourceType,LogicalId:LogicalResourceId,PhysicalId:PhysicalResourceId,Status:ResourceStatus}' --output table
96+
97+
echo ""
98+
echo "=== Stack Outputs ==="
99+
aws cloudformation describe-stacks --stack-name "$STACK_NAME" \
100+
--query 'Stacks[0].Outputs[].{Key:OutputKey,Value:OutputValue}' --output table 2>/dev/null || echo " (none)"
83101

84102
echo ""
85103
read -rp "Delete stack $STACK_NAME? (y/n): " CHOICE

deploy.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,18 @@ aws cloudformation deploy \
126126
--template-file "$TEMPLATE" \
127127
--stack-name "$STACK_NAME" \
128128
$CAPA_ARG \
129-
$OVERRIDES_ARG
129+
$OVERRIDES_ARG \
130+
--no-fail-on-empty-changeset
130131

131132
echo ""
132-
echo "Stack outputs:"
133+
echo "=== Stack Resources ==="
134+
aws cloudformation list-stack-resources --stack-name "$STACK_NAME" \
135+
--query 'StackResourceSummaries[].{Type:ResourceType,LogicalId:LogicalResourceId,PhysicalId:PhysicalResourceId,Status:ResourceStatus}' --output table 2>/dev/null || echo " (none)"
136+
137+
echo ""
138+
echo "=== Stack Outputs ==="
133139
aws cloudformation describe-stacks --stack-name "$STACK_NAME" \
134140
--query 'Stacks[0].Outputs[].{Key:OutputKey,Value:OutputValue}' --output table 2>/dev/null || echo " (none)"
135141

136142
echo ""
137-
echo "To delete: $0 --delete $TUT_DIR"
143+
echo "To delete: ./cleanup.sh $TUT_DIR"

0 commit comments

Comments
 (0)