Skip to content

fix(aws): destroy converges in one pass with VPC-attached Lambdas - #937

Merged
sam-goodwin merged 1 commit into
mainfrom
claude/aws-destroy-ordering-ca088a
Jul 24, 2026
Merged

sam-goodwin merged 1 commit into
mainfrom
claude/aws-destroy-ordering-ca088a

Conversation

@sam-goodwin

Copy link
Copy Markdown
Contributor

Fixes the destroy failure reported with https://github.com/xofromthemoon/alchemy-aws-demo — destroying a stack with a VPC-attached Lambda failed with subnets/security groups stuck on DependencyViolation (Waiting for dependencies to clear... (attempt 17)), forcing users to run destroy multiple times.

Root cause: DeleteFunction returns immediately, but the function's Hyperplane ENIs stay in-use in their subnets/security group for minutes and AWS's own reaper can take 20+ minutes to delete them after they detach (reproduced live: ENIs detached ~4 min after function delete and were still undeleted 12+ min later). The Subnet retry budget (~12 min) and SecurityGroup budget (~2.5 min) both expired first, failing the destroy even though deletion ordering was correct.

  • EC2/LingeringEnis.ts: shared retryWhileLingeringEnis — on every DependencyViolation, observe the ENIs still occupying the subnet/SG and explicitly delete detached Lambda ENIs instead of waiting for Lambda's reaper. While the blockers are Lambda ENIs (guaranteed to clear), the retry budget extends from ~12 min to ~25 min; other dependencies keep the base budget.

    // detached Hyperplane ENIs flip InterfaceType "lambda" -> "interface";
    // only the description still identifies them (same matching as Terraform)
    const isReapableEni = (eni) =>
      eni.InterfaceType === "lambda" ||
      eni.Description?.startsWith("AWS Lambda VPC ENI");
  • EC2/Subnet.ts, EC2/SecurityGroup.ts: delete paths now retry through the reaper (SecurityGroup's budget was previously only 30×5s).

  • Lambda/Function.ts: precreate no longer forwards news.vpc into CreateFunction — precreate props are unresolved, so an Output-valued subnet id crashed serialization (ParseError: Expected string, got PrivateSubnet1.subnetId). The stub is created without a VPC config; reconcile attaches the resolved config as before.

  • test/AWS/Lambda/VpcFunctionDestroy.test.ts: live regression test (FAST-gated) — deploys Network + SG + VPC-attached function, asserts one destroy removes everything including the VPC. Failed before the fix with the exact symptoms from the report; passes in a single pass with it.

Deleting a VPC-attached Lambda leaves Hyperplane ENIs in its subnets and
security group: they detach ~4 min after DeleteFunction, and AWS's own
reaper can take 20+ min to delete them. Subnet (~12 min) and SecurityGroup
(~2.5 min) DependencyViolation retry budgets expired first, failing destroy
and forcing users to run it multiple times.

- EC2/LingeringEnis: retryWhileLingeringEnis wraps Subnet/SecurityGroup
  deletes — on DependencyViolation it deletes detached Lambda ENIs
  explicitly (detached ENIs flip InterfaceType lambda->interface, so match
  by description like Terraform) and extends the budget to ~25 min only
  while the blockers are Lambda ENIs.
- Lambda/Function: precreate no longer forwards news.vpc into
  CreateFunction — precreate props are unresolved, so Output-valued subnet
  ids crashed serialization; reconcile attaches the resolved VPC config.
- test: live regression (FAST-gated) proving one destroy removes the
  whole Network + SG + VPC Lambda stack.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@alchemy-version-bot

Copy link
Copy Markdown
Contributor

Install the packages built from this commit:

alchemy

bun add alchemy@https://pkg.ing/alchemy/2c75115

@alchemy.run/better-auth

bun add @alchemy.run/better-auth@https://pkg.ing/@alchemy.run/better-auth/2c75115

@alchemy.run/pr-package

bun add @alchemy.run/pr-package@https://pkg.ing/@alchemy.run/pr-package/2c75115

@sam-goodwin
sam-goodwin merged commit 4b5d7ec into main Jul 24, 2026
9 checks passed
@sam-goodwin
sam-goodwin deleted the claude/aws-destroy-ordering-ca088a branch July 24, 2026 08:16
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.

1 participant