Skip to content

Improve companion stack sweeper function#3931

Merged
vicheey merged 5 commits into
developfrom
improve-companion-stack-sweeper-function
May 28, 2026
Merged

Improve companion stack sweeper function#3931
vicheey merged 5 commits into
developfrom
improve-companion-stack-sweeper-function

Conversation

@vicheey
Copy link
Copy Markdown
Contributor

@vicheey vicheey commented May 28, 2026

Issue #, if available

N/A

Description of changes

  • Add API Gateway REST API cleanup phase to the sweeper function — deletes orphaned REST APIs matching sam-integ- pattern before stack deletion to avoid rate limit issues on DeleteRestApi (1 per 30s control plane limit, using 35s sleep).
  • Add 8-minute time cap for the API phase to ensure stacks and log groups still get cleaned up.
  • Unify pattern matching to a single TEST_PATTERN = 'sam-integ-' (removes dual STACK_PATTERN/IAM_PATTERN).
  • Reduce cutoff age from 24h to 6h (aligns with the 6h sweep schedule).
  • Replace deletion counters with per-resource print(f"Deleting: {name}") logging.
  • Add apigateway:DELETE IAM permission to the sweeper role.

Description of how you validated changes

Deployed companion stack to personal account (us-west-2).

Checklist

Examples?

Please reach out in the comments if you want to add an example. Examples will be
added to sam init through aws/aws-sam-cli-app-templates.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

vicheey added 2 commits May 28, 2026 11:52
Delete orphaned REST APIs matching sam-integ- pattern before stack
deletion to avoid rate limit issues. Uses 35s sleep between API
deletions per API Gateway control plane limits. Also unifies pattern
matching to a single TEST_PATTERN and reduces cutoff to 6 hours.
Prevents the API deletion loop (35s sleep per API) from consuming
the entire Lambda budget, ensuring stacks and log groups still get
cleaned up in the remaining 7 minutes.
@vicheey vicheey requested a review from a team as a code owner May 28, 2026 19:07
Copy link
Copy Markdown
Collaborator

@aws-sam-cli-bot aws-sam-cli-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Results

Reviewed: 34f5496..1c15bae
Files: 1
Comments: 1

Comment thread integration/setup/companion-stack.yaml
Ensures the 35s sleep runs even when delete_rest_api throws
(e.g. TooManyRequestsException), preventing back-to-back failing
calls that would worsen throttling.
Comment thread integration/setup/companion-stack.yaml Outdated
Comment thread integration/setup/companion-stack.yaml Outdated
Comment thread integration/setup/companion-stack.yaml Outdated
Comment thread integration/setup/companion-stack.yaml
Comment thread integration/setup/companion-stack.yaml
Comment thread integration/setup/companion-stack.yaml
Comment thread integration/setup/companion-stack.yaml
More frequent sweeps reduce orphaned resource accumulation and
align better with the 6-hour age cutoff for cleanup eligibility.
Copy link
Copy Markdown
Collaborator

@aws-sam-cli-bot aws-sam-cli-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Results

Reviewed: 34f5496..56d4dc8
Files: 1
Comments: 1

Comment thread integration/setup/companion-stack.yaml
Ensures _sweep_stacks and _sweep_logs still run even if
_sweep_apis encounters an unexpected error like pagination
failure.
@vicheey vicheey enabled auto-merge (squash) May 28, 2026 22:00
@vicheey vicheey disabled auto-merge May 28, 2026 22:58
@vicheey vicheey closed this May 28, 2026
@vicheey vicheey reopened this May 28, 2026
@vicheey vicheey enabled auto-merge (squash) May 28, 2026 23:00
Copy link
Copy Markdown
Collaborator

@aws-sam-cli-bot aws-sam-cli-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Results

Reviewed: 34f5496..7cc973b
Files: 1
Comments: 1

Comment thread integration/setup/companion-stack.yaml
@vicheey vicheey merged commit 1d4cc7c into develop May 28, 2026
15 of 16 checks passed
@vicheey vicheey deleted the improve-companion-stack-sweeper-function branch May 28, 2026 23:45
@vicheey vicheey requested a review from aws-sam-cli-bot May 28, 2026 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants