Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

feat(cloudformation): NextToken on the list and describe actions (#1654)

iot-rocket064b76288bcd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f06d6ec2..7e64eb9e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
- **S3 — the Multi-Region Access Point alias starts with a letter and follows the documented pattern** — the alias was the first 13 hex characters of a uuid, so it could come out as digits only (`1240729989764.mrap`), which is not what S3 mints (`mfzwi23gnjvgw.mrap`) and made `test_cfn_s3_multi_region_access_point` fail whenever no letter was drawn (`str.islower()` is False without a cased character). The alias now follows the documented pattern `^[a-z][a-z0-9]*[.]mrap$`: a letter, then twelve lowercase letters or digits; the test checks that pattern. Contributed by @iot-rocket.
### Added
- **CloudFormation — `ListImports`, `UpdateTerminationProtection`, `SetStackPolicy`, `GetStackPolicy`, `CancelUpdateStack` and `ContinueUpdateRollback`** — the first four were routed to the service and answered `InvalidAction`, the last two did not exist, so a stack in `UPDATE_ROLLBACK_FAILED` had no way out short of a reset. `ListImports` names the stacks importing an export (a `ValidationError` when none does); termination protection is set on create or later and makes `DeleteStack` refuse with the stack unchanged (`DescribeStacks` reports `EnableTerminationProtection`); a stack policy is stored and returned (it is not enforced); `CancelUpdateStack` stops an `UPDATE_IN_PROGRESS` update before its next resource and rolls it back ("User Initiated"); `ContinueUpdateRollback` retries the deletes that failed the rollback, skips the `ResourcesToSkip` (their status becomes `UPDATE_COMPLETE`, the resource stays) and lands the stack in `UPDATE_ROLLBACK_COMPLETE`. Contributed by @iot-rocket.
+- **CloudFormation — the list and describe actions page their results** — `DescribeStacks`, `ListStacks`, `DescribeStackEvents`, `ListStackResources`, `ListExports`, `ListImports` and `ListChangeSets` answered the whole store in one response and ignored `NextToken`, so a paginator drained nothing and a caller that pages (`ListExports` pages at 100 values on AWS, the others at 1 MB) never saw a second page. They now return 100 items per page with a `NextToken` for the rest; a token the service did not hand out is a `ValidationError`. `DescribeStackEvents` also orders events of one millisecond newest first, so the pages are strictly reverse-chronological. Contributed by @iot-rocket.
- **CloudFormation — `DescribeStackResource` returns the resource `Metadata`** — the `Metadata` attribute of a resource was accepted and never returned; `StackResourceDetail` now carries it as a JSON string with intrinsics interpreted, as the API reference defines it (a CDK stack's `aws:cdk:path` is the common case); a `Metadata` that resolves away or cannot be resolved comes back as declared. Contributed by @iot-rocket.
### Fixed
- **CloudFormation — parameter constraints are enforced** — `AllowedPattern`, `MinLength`, `MaxLength`, `MinValue` and `MaxValue` were ignored (only `AllowedValues` was checked), so a value a real account refuses deployed locally. They are checked before a stack exists, with CloudFormation's message (`Parameter 'P' must match pattern ^[a-z]+$`, measured) and a `ConstraintDescription` in place of the reason; a `CommaDelimitedList` is matched per member and a `List<Number>` is validated as numbers. Contributed by @iot-rocket.
diff --git a/ministack/services/cloudformation/changesets.py b/ministack/services/cloudformation/changesets.py
index 301ffb35..42cb5e7e 100644
--- a/ministack/services/cloudformation/changesets.py
+++ b/ministack/services/cloudformation/changesets.py
@@ -17,7 +17,7 @@ from .engine import (
_resolve_refs,
validate_template_support,
)
-from .helpers import _error, _esc, _extract_members, _p, _resolve_template, _xml
+from .helpers import _error, _esc, _extract_members, _p, _page, _resolve_template, _xml
from .stacks import (
_add_event,
_create_stack_task_in_region,
@@ -466,10 +466,12 @@ def _list_change_sets(params):
if not stack_name:
return _error("ValidationError", "StackName is required")
+ listed = [cs for cs in _change_sets.values() if cs["StackName"] == stack_name]
+ listed, next_token_xml, err = _page(listed, params, "ListChangeSets")
+ if err:
+ return err
members = ""
- for cs in _change_sets.values():
- if cs["StackName"] != stack_name:
- continue
+ for cs in listed:
members += (
"<member>"
f"<ChangeSetId>{_esc(cs['ChangeSetId'])}</ChangeSetId>"
@@ -487,7 +489,7 @@ def _list_change_sets(params):
return _xml(200, "ListChangeSetsResponse",
f"<ListChangeSetsResult>"
f"<Summaries>{members}</Summaries>"
- f"</ListChangeSetsResult>")
+ f"{next_token_xml}</ListChangeSetsResult>")
# --- GetTemplateSummary ---
diff --git a/ministack/services/cloudformation/handlers.py b/ministack/services/cloudformation/handlers.py
index 227925de..b0c3baaf 100644
--- a/ministack/services/cloudformation/handlers.py
+++ b/ministack/services/cloudformation/handlers.py
@@ -34,6 +34,7 @@ from .helpers import (
_extract_stack_status_filters,
_extract_string_members,
_p,
+ _page,
_resolve_template,
_xml,
)
@@ -210,6 +211,9 @@ def _describe_stacks(params):
if s.get("StackStatus") != "DELETE_COMPLETE"
]
+ stacks_to_describe, next_token_xml, err = _page(stacks_to_describe, params, "DescribeStacks")
+ if err:
+ return err
members = ""
for s in stacks_to_describe:
params_xml = ""
@@ -265,7 +269,8 @@ def _describe_stacks(params):
)
return _xml(200, "DescribeStacksResponse",
- f"<DescribeStacksResult><Stacks>{members}</Stacks></DescribeStacksResult>")
+ f"<DescribeStacksResult><Stacks>{members}</Stacks>"
+ f"{next_token_xml}</DescribeStacksResult>")
# --- ListStacks ---
@@ -273,12 +278,17 @@ def _describe_stacks(params):
def _list_stacks(params):
from ministack.services.cloudformation import _stacks
status_filters = _extract_stack_status_filters(params)
+ listed = [
+ s for s in _stacks.values()
+ if not status_filters or s.get("StackStatus", "") in status_filters
+ ]
+ listed, next_token_xml, err = _page(listed, params, "ListStacks")
+ if err:
+ return err
summaries = ""
- for s in _stacks.values():
+ for s in listed:
status = s.get("StackStatus", "")
- if status_filters and status not in status_filters:
- continue
entry = (
"<member>"
f"<StackName>{_esc(s['StackName'])}</StackName>"
@@ -296,7 +306,8 @@ def _list_stacks(params):
summaries += entry
return _xml(200, "ListStacksResponse",
- f"<ListStacksResult><StackSummaries>{summaries}</StackSummaries></ListStacksResult>")
+ f"<ListStacksResult><StackSummaries>{summaries}</StackSummaries>"
+ f"{next_token_xml}</ListStacksResult>")
# --- DescribeStackEvents ---
@@ -314,9 +325,16 @@ def _describe_stack_events(params):
stack_id = stack["StackId"]
events = _stack_events.get(stack_id, [])
- # Newest first
- events_sorted = sorted(events, key=lambda e: e.get("Timestamp", ""),
- reverse=True)
+ # Newest first; events of one millisecond in reverse emission order
+ events_sorted = [
+ e for _, e in sorted(
+ enumerate(events),
+ key=lambda pair: (pair[1].get("Timestamp", ""), pair[0]),
+ reverse=True)
+ ]
+ events_sorted, next_token_xml, err = _page(events_sorted, params, "DescribeStackEvents")
+ if err:
+ return err
members = ""
for e in events_sorted:
@@ -335,7 +353,8 @@ def _describe_stack_events(params):
)
return _xml(200, "DescribeStackEventsResponse",
- f"<DescribeStackEventsResult><StackEvents>{members}</StackEvents></DescribeStackEventsResult>")
+ f"<DescribeStackEventsResult><StackEvents>{members}</StackEvents>"
+ f"{next_token_xml}</DescribeStackEventsResult>")
# --- DescribeStackResource ---
@@ -466,8 +485,11 @@ def _list_stack_resources(params):
f"Stack [{stack_name}] does not exist")
resources = stack.get("_resources", {})
+ listed, next_token_xml, err = _page(list(resources.items()), params, "ListStackResources")
+ if err:
+ return err
members = ""
- for logical_id, res in resources.items():
+ for logical_id, res in listed:
members += (
"<member>"
f"<LogicalResourceId>{_esc(logical_id)}</LogicalResourceId>"
@@ -481,7 +503,7 @@ def _list_stack_resources(params):
return _xml(200, "ListStackResourcesResponse",
f"<ListStackResourcesResult>"
f"<StackResourceSummaries>{members}</StackResourceSummaries>"
- f"</ListStackResourcesResult>")
+ f"{next_token_xml}</ListStackResourcesResult>")
# --- GetTemplate ---
@@ -814,8 +836,11 @@ def _validate_template(params):
def _list_exports(params):
from ministack.services.cloudformation import _exports
+ listed, next_token_xml, err = _page(list(_exports.items()), params, "ListExports")
+ if err:
+ return err
members = ""
- for name, exp in _exports.items():
+ for name, exp in listed:
members += (
"<member>"
f"<ExportingStackId>{_esc(exp.get('StackId', ''))}</ExportingStackId>"
@@ -825,7 +850,8 @@ def _list_exports(params):
)
return _xml(200, "ListExportsResponse",
- f"<ListExportsResult><Exports>{members}</Exports></ListExportsResult>")
+ f"<ListExportsResult><Exports>{members}</Exports>"
+ f"{next_token_xml}</ListExportsResult>")
# --- GetTemplateSummary ---
def _get_template_summary(params):
@@ -951,9 +977,13 @@ def _list_imports(params):
if not importers:
return _error("ValidationError",
f"Export '{export_name}' is not imported by any stack.")
+ importers, next_token_xml, err = _page(importers, params, "ListImports")
+ if err:
+ return err
members = "".join(f"<member>{_esc(n)}</member>" for n in importers)
return _xml(200, "ListImportsResponse",
- f"<ListImportsResult><Imports>{members}</Imports></ListImportsResult>")
+ f"<ListImportsResult><Imports>{members}</Imports>"
+ f"{next_token_xml}</ListImportsResult>")
# --- UpdateTerminationProtection / stack policy ---
diff --git a/ministack/services/cloudformation/helpers.py b/ministack/services/cloudformation/helpers.py
index 807dda6f..b0110650 100644
--- a/ministack/services/cloudformation/helpers.py
+++ b/ministack/services/cloudformation/helpers.py
@@ -132,3 +132,35 @@ def _extract_string_members(params, prefix):
result.append(value)
i += 1
return result
+
+
+PAGE_SIZE = 100
+
+
+def _page(items, params, action):
+ """Cut ``items`` down to the page a request asks for.
+
+ Real CloudFormation pages ``ListExports`` at 100 values and the other
+ list and describe actions at 1 MB of output; here every one of them pages
+ at 100 items. The token is ``<Action>:<offset of the next page>``, so a
+ token of one action is refused by another. Returns
+ ``(page, next_token_xml, error)`` — ``next_token_xml`` is empty on the
+ last page and ``error`` is the response for a token the service did not
+ hand out.
+
+ The offset is taken over the store as it is at the time of the call: an
+ item added or removed between two pages shifts the later pages, so an
+ item can be skipped or repeated (events are listed newest first, so an
+ appended event shifts every offset by one)."""
+ token = _p(params, "NextToken")
+ start = 0
+ if token:
+ tagged, _, offset = token.partition(":")
+ if tagged != action or not offset.isdigit():
+ return [], "", _error("ValidationError", "Invalid NextToken")
+ start = int(offset)
+ page = items[start:start + PAGE_SIZE]
+ next_token_xml = ""
+ if start + PAGE_SIZE < len(items):
+ next_token_xml = f"<NextToken>{action}:{start + PAGE_SIZE}</NextToken>"
+ return page, next_token_xml, None
diff --git a/tests/test_cfn.py b/tests/test_cfn.py
index 8cc108c9..367ad515 100644
--- a/tests/test_cfn.py
+++ b/tests/test_cfn.py
@@ -100,6 +100,15 @@ def _delete_cfn_test_stack(cfn, stack_name):
pass
+def _all_pages(client, operation, key, **kwargs):
+ """Every item of a list action; the service pages at 100 items."""
+ return [
+ item
+ for page in client.get_paginator(operation).paginate(**kwargs)
+ for item in page[key]
+ ]
+
+
def _output(stack, key):
return next(o["OutputValue"] for o in stack["Outputs"] if o["OutputKey"] == key)
@@ -107,7 +116,8 @@ def _output(stack, key):
def _stack_event_reasons(cfn, stack_name):
return " ".join(
e.get("ResourceStatusReason", "")
- for e in cfn.describe_stack_events(StackName=stack_name)["StackEvents"]
+ for e in _all_pages(cfn, "describe_stack_events", "StackEvents",
+ StackName=stack_name)
)
@@ -141,10 +151,12 @@ def test_cfn_region_scopes_stacks_change_sets_and_events():
assert ":us-west-2:" in west_stack["StackId"]
east_described_ids = {
- stack["StackId"] for stack in east.describe_stacks()["Stacks"]
+ stack["StackId"]
+ for stack in _all_pages(east, "describe_stacks", "Stacks")
}
west_described_ids = {
- stack["StackId"] for stack in west.describe_stacks()["Stacks"]
+ stack["StackId"]
+ for stack in _all_pages(west, "describe_stacks", "Stacks")
}
assert east_stack["StackId"] in east_described_ids
assert west_stack["StackId"] not in east_described_ids
@@ -152,10 +164,12 @@ def test_cfn_region_scopes_stacks_change_sets_and_events():
assert east_stack["StackId"] not in west_described_ids
east_listed_ids = {
- stack["StackId"] for stack in east.list_stacks()["StackSummaries"]
+ stack["StackId"]
+ for stack in _all_pages(east, "list_stacks", "StackSummaries")
}
west_listed_ids = {
- stack["StackId"] for stack in west.list_stacks()["StackSummaries"]
+ stack["StackId"]
+ for stack in _all_pages(west, "list_stacks", "StackSummaries")
}
assert east_stack["StackId"] in east_listed_ids
assert west_stack["StackId"] not in east_listed_ids
@@ -251,10 +265,10 @@ def test_cfn_region_scopes_exports_imports_and_delete_checks():
assert producer["StackStatus"] == "CREATE_COMPLETE"
assert {
export["Name"]: export["Value"]
- for export in east.list_exports()["Exports"]
+ for export in _all_pages(east, "list_exports", "Exports")
}[export_name] == "east-value"
assert export_name not in {
- export["Name"] for export in west.list_exports()["Exports"]
+ export["Name"] for export in _all_pages(west, "list_exports", "Exports")
}
with pytest.raises(ClientError) as exc:
west.describe_stacks(StackName=producer_name)
@@ -286,6 +300,183 @@ def test_cfn_region_scopes_exports_imports_and_delete_checks():
_delete_cfn_test_stack(west, decoy_name)
+def test_cfn_list_actions_page_at_one_hundred(cfn):
+ suffix = _uuid_mod.uuid4().hex[:8]
+ stack_name = f"cfn-paging-{suffix}"
+ template = {
+ "Resources": {
+ f"P{i}": {
+ "Type": "AWS::SSM::Parameter",
+ "Properties": {
+ "Type": "String",
+ "Name": f"/cfn-paging/{suffix}/{i}",
+ "Value": str(i),
+ },
+ }
+ for i in range(101)
+ }
+ }
+ cfn.create_stack(StackName=stack_name, TemplateBody=json.dumps(template))
+ try:
+ assert _wait_stack(cfn, stack_name)["StackStatus"] == "CREATE_COMPLETE"
+
+ # 101 resources: two pages, the token only on the first one.
+ first = cfn.list_stack_resources(StackName=stack_name)
+ assert len(first["StackResourceSummaries"]) == 100
+ second = cfn.list_stack_resources(
+ StackName=stack_name, NextToken=first["NextToken"])
+ assert len(second["StackResourceSummaries"]) == 1
+ assert "NextToken" not in second
+ logical_ids = {r["LogicalResourceId"] for r in first["StackResourceSummaries"]}
+ logical_ids |= {r["LogicalResourceId"] for r in second["StackResourceSummaries"]}
+ assert logical_ids == set(template["Resources"])
+ assert len(_all_pages(cfn, "list_stack_resources", "StackResourceSummaries",
+ StackName=stack_name)) == 101
+ assert "NextToken" not in cfn.describe_stacks(StackName=stack_name)
+
+ # Two events per resource plus the stack's own: three pages, newest first
+ # across the page boundary.
+ pages = list(cfn.get_paginator("describe_stack_events").paginate(
+ StackName=stack_name))
+ assert len(pages) == 3
+ assert [len(page["StackEvents"]) for page in pages[:2]] == [100, 100]
+ events = [e for page in pages for e in page["StackEvents"]]
+ assert len({e["EventId"] for e in events}) == len(events) > 200
+ timestamps = [e["Timestamp"] for e in events]
+ assert timestamps == sorted(timestamps, reverse=True)
+ # The stack's own CREATE_IN_PROGRESS is the oldest event and lands on
+ # the last page (events of one millisecond keep their emission order).
+ stack_start = [
+ e for e in pages[-1]["StackEvents"]
+ if e["ResourceType"] == "AWS::CloudFormation::Stack"
+ and e["ResourceStatus"] == "CREATE_IN_PROGRESS"
+ ]
+ assert len(stack_start) == 1
+ assert stack_start[0]["Timestamp"] == min(timestamps)
+ finally:
+ _delete_cfn_test_stack(cfn, stack_name)
+
+
+def test_cfn_list_exports_pages_at_one_hundred(cfn):
+ suffix = _uuid_mod.uuid4().hex[:8]
+ stack_name = f"cfn-paging-exports-{suffix}"
+ template = {
+ "Resources": {
+ "P": {
+ "Type": "AWS::SSM::Parameter",
+ "Properties": {
+ "Type": "String",
+ "Name": f"/cfn-paging-exports/{suffix}",
+ "Value": "v",
+ },
+ }
+ },
+ "Outputs": {
+ f"O{i}": {"Value": str(i), "Export": {"Name": f"cfn-paging-{suffix}-{i}"}}
+ for i in range(101)
+ },
+ }
+ cfn.create_stack(StackName=stack_name, TemplateBody=json.dumps(template))
+ try:
+ assert _wait_stack(cfn, stack_name)["StackStatus"] == "CREATE_COMPLETE"
+ pages = list(cfn.get_paginator("list_exports").paginate())
+ assert len(pages) >= 2
+ assert all(len(page["Exports"]) == 100 for page in pages[:-1])
+ assert "NextToken" not in pages[-1]
+ names = {e["Name"] for page in pages for e in page["Exports"]}
+ assert {f"cfn-paging-{suffix}-{i}" for i in range(101)} <= names
+ finally:
+ _delete_cfn_test_stack(cfn, stack_name)
+
+
+def test_cfn_list_imports_and_change_sets_take_a_token(cfn):
+ suffix = _uuid_mod.uuid4().hex[:8]
+ producer = f"cfn-paging-producer-{suffix}"
+ consumer = f"cfn-paging-consumer-{suffix}"
+ export_name = f"cfn-paging-export-{suffix}"
+ producer_template = {
+ "Resources": {"Q": {"Type": "AWS::SQS::Queue"}},
+ "Outputs": {"Q": {"Value": {"Ref": "Q"}, "Export": {"Name": export_name}}},
+ }
+ consumer_template = {
+ "Resources": {
+ "P": {
+ "Type": "AWS::SSM::Parameter",
+ "Properties": {
+ "Type": "String",
+ "Name": f"/cfn-paging-consumer/{suffix}",
+ "Value": {"Fn::ImportValue": export_name},
+ },
+ }
+ }
+ }
+ cfn.create_stack(StackName=producer, TemplateBody=json.dumps(producer_template))
+ try:
+ assert _wait_stack(cfn, producer)["StackStatus"] == "CREATE_COMPLETE"
+ cfn.create_stack(StackName=consumer, TemplateBody=json.dumps(consumer_template))
+ try:
+ assert _wait_stack(cfn, consumer)["StackStatus"] == "CREATE_COMPLETE"
+ assert _all_pages(cfn, "list_imports", "Imports",
+ ExportName=export_name) == [consumer]
+ assert "NextToken" not in cfn.list_imports(ExportName=export_name)
+ # The token is checked once the export is known to be imported.
+ with pytest.raises(ClientError) as exc:
+ cfn.list_imports(ExportName=export_name, NextToken="ListStacks:0")
+ assert exc.value.response["Error"]["Code"] == "ValidationError"
+ assert "NextToken" in exc.value.response["Error"]["Message"]
+ with pytest.raises(ClientError) as exc:
+ cfn.list_imports(ExportName=f"{export_name}-unused", NextToken="ListStacks:0")
+ assert "not imported" in exc.value.response["Error"]["Message"]
+
+ cfn.create_change_set(
+ StackName=producer, ChangeSetName=f"cs-{suffix}",
+ ChangeSetType="UPDATE",
+ TemplateBody=json.dumps({**producer_template, "Description": "changed"}),
+ )
+ listed = cfn.list_change_sets(StackName=producer)
+ assert [cs["ChangeSetName"] for cs in listed["Summaries"]] == [f"cs-{suffix}"]
+ assert "NextToken" not in listed
+ assert _all_pages(cfn, "list_change_sets", "Summaries",
+ StackName=producer) == listed["Summaries"]
+ with pytest.raises(ClientError) as exc:
+ cfn.list_change_sets(StackName=producer, NextToken="ListStacks:0")
+ assert exc.value.response["Error"]["Code"] == "ValidationError"
+ assert "NextToken" in exc.value.response["Error"]["Message"]
+ finally:
+ _delete_cfn_test_stack(cfn, consumer)
+ finally:
+ _delete_cfn_test_stack(cfn, producer)
+
+
+def test_cfn_list_actions_offset_past_the_end_is_an_empty_page(cfn):
+ listed = cfn.list_stacks(NextToken="ListStacks:999999")
+ assert listed["StackSummaries"] == []
+ assert "NextToken" not in listed
+ exports = cfn.list_exports(NextToken="ListExports:999999")
+ assert exports["Exports"] == []
+ assert "NextToken" not in exports
+
+
+ ("operation", "token"),
+ [
+ ("list_stacks", "not-a-token"),
+ ("describe_stacks", "not-a-token"),
+ ("list_exports", "not-a-token"),
+ ("list_exports", "ListStacks:100"),
+ ("list_stacks", "ListStacks:hundred"),
+ ("describe_stacks", "DescribeStacks:"),
+ ],
+)
+def test_cfn_list_actions_refuse_a_foreign_next_token(cfn, operation, token):
+ """A token is ``<Action>:<offset>``; anything else, a token of another
+ action included, is refused before a page is built."""
+ with pytest.raises(ClientError) as exc:
+ getattr(cfn, operation)(NextToken=token)
+ assert exc.value.response["Error"]["Code"] == "ValidationError"
+ assert "NextToken" in exc.value.response["Error"]["Message"]
+
+
def test_cfn_nested_stack_stays_in_parent_region():
suffix = _uuid_mod.uuid4().hex[:8]
parent_name = f"cfn-regional-parent-{suffix}"
@@ -341,7 +532,7 @@ def test_cfn_nested_stack_stays_in_parent_region():
child = next(
stack
- for stack in west.describe_stacks()["Stacks"]
+ for stack in _all_pages(west, "describe_stacks", "Stacks")
if stack["StackName"].startswith(f"{parent_name}-Nested-")
)
assert ":us-west-2:" in child["StackId"]
@@ -1899,7 +2090,7 @@ def test_cfn_outputs_exports(cfn):
cfn.create_stack(StackName="cfn-t05", TemplateBody=json.dumps(template))
_wait_stack(cfn, "cfn-t05")
- exports = cfn.list_exports()["Exports"]
+ exports = _all_pages(cfn, "list_exports", "Exports")
assert any(e["Name"] == "cfn-t05-bucket-export" for e in exports)
@@ -2309,7 +2500,7 @@ def test_cfn_list_stacks(cfn):
_wait_stack(cfn, "cfn-t12-a")
_wait_stack(cfn, "cfn-t12-b")
- summaries = cfn.list_stacks()["StackSummaries"]
+ summaries = _all_pages(cfn, "list_stacks", "StackSummaries")
names = [s["StackName"] for s in summaries]
assert "cfn-t12-a" in names
assert "cfn-t12-b" in names
@@ -2791,7 +2982,7 @@ def test_cfn_e2e_pipeline(cfn_e2e_stack, s3, sqs, sns):
assert "MessageId" in resp
def test_cfn_e2e_exports_available(cfn_e2e_stack, cfn):
- exports = cfn.list_exports()["Exports"]
+ exports = _all_pages(cfn, "list_exports", "Exports")
names = {e["Name"]: e["Value"] for e in exports}
assert f"{_E2E_STACK}-bucket" in names
assert names[f"{_E2E_STACK}-bucket"] == cfn_e2e_stack["BucketName"]
@@ -3862,7 +4053,7 @@ def test_cfn_stack_with_s3_lambda_dynamodb(cfn, s3, lam, ddb):
# Delete stack and verify cleanup
cfn.delete_stack(StackName=stack_name)
time.sleep(2)
- stacks = cfn.describe_stacks()["Stacks"]
+ stacks = _all_pages(cfn, "describe_stacks", "Stacks")
active = [st for st in stacks if st["StackName"] == stack_name and "DELETE" not in st["StackStatus"]]
assert len(active) == 0
@@ -10847,7 +11038,8 @@ def test_cfn_stack_delete_failed_keeps_exports(cfn, lam):
stack = _wait_stack(cfn, stack_name)
assert stack["StackStatus"] == "DELETE_FAILED"
- exports = {e["Name"]: e["Value"] for e in cfn.list_exports()["Exports"]}
+ exports = {e["Name"]: e["Value"]
+ for e in _all_pages(cfn, "list_exports", "Exports")}
assert exports.get(export_name) == "still-here"
# The completed retry removes the export with the stack.
@@ -10855,7 +11047,7 @@ def test_cfn_stack_delete_failed_keeps_exports(cfn, lam):
cfn.delete_stack(StackName=stack_name)
stack = _wait_stack(cfn, stack_name)
assert stack["StackStatus"] == "DELETE_COMPLETE"
- exports = {e["Name"] for e in cfn.list_exports()["Exports"]}
+ exports = {e["Name"] for e in _all_pages(cfn, "list_exports", "Exports")}
assert export_name not in exports
finally:
_delete_cfn_test_stack(cfn, stack_name)
@@ -12212,7 +12404,7 @@ def test_cfn_unrecognized_resource_type_rejected_up_front(cfn, sqs):
with pytest.raises(ClientError) as exc:
cfn.describe_stacks(StackName=name)
assert "does not exist" in str(exc.value)
- assert not [s for s in cfn.list_stacks()["StackSummaries"]
+ assert not [s for s in _all_pages(cfn, "list_stacks", "StackSummaries")
if s["StackName"] == name]
# The valid sibling was never provisioned.
assert not [u for u in sqs.list_queues().get("QueueUrls", [])
@@ -12319,9 +12511,9 @@ def test_cfn_getatt_unknown_attribute_fails_the_stack(cfn, sqs):
"for AWS::SQS::Queue" in r for r in reasons), reasons
with pytest.raises(ClientError):
sqs.get_queue_url(QueueName="cfn-preflight-getatt-q")
- assert not cfn.list_exports()["Exports"] or all(
+ assert all(
e["ExportingStackId"] != cfn.describe_stacks(StackName=name)["Stacks"][0]["StackId"]
- for e in cfn.list_exports()["Exports"])
+ for e in _all_pages(cfn, "list_exports", "Exports"))
finally:
cfn.delete_stack(StackName=name)
_wait_stack(cfn, name)