Skip to content

CloudFormation: DeleteStack and DescribeStacks do not resolve a stack ARN, only a name #544

Closed

Description

@scttfrdmn

Against ghcr.io/scttfrdmn/substrate:0.88.0, CloudFormation resolves a stack by
name only. Passing the stack's own ARN — the value create_stack and
describe_stacks both hand back — fails, and the delete_stack case fails
silently with HTTP 200.

Real CloudFormation accepts either form for StackName. The
API reference
is explicit: "The name or the unique stack ID that's associated with the stack."

Reproducer

import boto3

cfn = boto3.client(
    "cloudformation",
    endpoint_url="http://localhost:4566",
    region_name="us-east-1",
    aws_access_key_id="test",
    aws_secret_access_key="test",
)

TEMPLATE = """
Resources:
  Bucket:
    Type: AWS::S3::Bucket
"""

arn = cfn.create_stack(StackName="arn-probe", TemplateBody=TEMPLATE)["StackId"]
print("StackId:", arn)
cfn.get_waiter("stack_create_complete").wait(StackName="arn-probe")

# 1. describe by ARN -> ValidationError, though this is the ARN substrate returned
try:
    cfn.describe_stacks(StackName=arn)
    print("describe by ARN: ok")
except Exception as e:
    print("describe by ARN:", type(e).__name__, e)

# 2. delete by ARN -> HTTP 200, and the stack is still there
resp = cfn.delete_stack(StackName=arn)
print("delete by ARN HTTP:", resp["ResponseMetadata"]["HTTPStatusCode"])
print("still present:", [
    s["StackName"] for s in cfn.describe_stacks()["Stacks"]
    if s["StackName"] == "arn-probe"
])

# 3. delete by name -> gone
cfn.delete_stack(StackName="arn-probe")
print("after delete by name:", [
    s["StackName"] for s in cfn.describe_stacks()["Stacks"]
    if s["StackName"] == "arn-probe"
])

Observed:

StackId: arn:aws:cloudformation:us-east-1:123456789012:stack/arn-probe/...
describe by ARN: ClientError An error occurred (ValidationError) ... does not exist
delete by ARN HTTP: 200
still present: ['arn-probe']
after delete by name: []

Why the silent case matters

The delete_stack half is the damaging one, because nothing signals failure. A
caller that stores the StackId it was given — which is the natural thing to store,
since it is what identifies the stack unambiguously — and later deletes by it sees
HTTP 200 and reasonably concludes the stack is gone.

That is exactly what happened downstream in
parsl-ephemeral-provider:
its detached mode keeps the bastion's StackId and calls
delete_stack(StackName=self.bastion_id) in teardown. Against substrate the teardown
became a silent no-op, and the failure surfaced one test later as AlreadyExists on
the next stack create — a confusing place to debug from, several steps removed from
the call that actually did nothing.

Found while moving that project's integration suite off moto and onto substrate
(parsl-ephemeral-provider#183).

Suggested fix

Resolve StackName through the same lookup for both forms: if the value parses as a
stack ARN, extract the stack name (and ideally match the stack ID, so a stale ARN for
a deleted-and-recreated stack is rejected rather than silently retargeted). At
minimum, an unresolvable StackName should raise ValidationError from
delete_stack rather than return 200 — a delete that does nothing should not report
success.

Activity

  1. added
    type: bug
    area: cloudformation
    priority: high
    on Aug 3, 2026
  2. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    Reproduced exactly as reported, against v0.89.0. The delete_stack half is the serious
    one, and it is now sharper than when this was filed: v0.89.0 shipped the resource sweep
    (#518), so a by-name delete really does tear down the stack's resources — while a
    by-ARN delete still answers 200 and does nothing at all. The gap between the two
    widened.

    StackId returned by CreateStack:
      arn:aws:cloudformation:us-east-1:123456789012:stack/arn-probe/6c120a6f-…
    
    describe-stacks --stack-name <that ARN>   → ValidationError, "does not exist"
    delete-stack    --stack-name <that ARN>   → exit 0, no output, nothing deleted
    describe-stacks --stack-name arn-probe    → CREATE_COMPLETE   (still there)
    create-stack    --stack-name arn-probe    → AlreadyExists     (the downstream symptom)
    delete-stack    --stack-name arn-probe    → sweeps; head-bucket → 404
    

    This is precisely the defect shape v0.89.0 was built around — substrate reports a
    successful deletion of something it did not delete
    — reached by a different route. An ARN
    substrate itself minted and handed to the caller is not accepted back as an identifier.

    Cause, measured. Every read goes through d.state.Get(ctx, cfnNamespace, "stack:"+stackName)
    with the caller's string used verbatim as the key: 8 call sites in emulator/cfn_deployer.go
    (:1096, 1163, 1203, 1222, 1451, 1502, 1632, 1717) and 1 in emulator/cfn_rollback.go. The
    ARN is built by cfnStackARN (cfn_deployer.go:4530) from a cfnDeterministicUUID, so the
    name is recoverable from the ARN — nothing needs to be stored to fix this. The fix is one
    shared resolver
    that normalises an ARN to its stack name before the lookup, not nine edits.

    DeleteStack (:1119) then compounds it: an unresolvable name is deliberately treated as
    success — deleting an absent stack is a success — which is right for a genuinely absent
    stack and wrong for an identifier it simply failed to parse. That is the whole reason the
    ARN case answers 200 while deleting nothing. The resolver has to run before that
    tolerance applies.

    One correction to the report: the ARN in a ValidationError message should name the stack
    as given, but real CloudFormation's DescribeStacks accepts either form, so both the error
    path and the success path change here.

    Milestoned for v0.90.0 with priority: high.

  3. added this to the v0.90.0 milestone on Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: cloudformationfidelitypriority: hightype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions