from typing import Any import boto3 from botocore.exceptions import ClientError def stack_status(region: str, profile: str, stack_name: str) -> dict[str, Any] | None: client = boto3.Session(profile_name=profile, region_name=region).client("cloudformation") try: stack = client.describe_stacks(StackName=stack_name)["Stacks"][0] except ClientError as e: message = e.response.get("Error", {}).get("Message", "") if "does not exist" in message: return None raise return { "name": stack["StackName"], "status": stack["StackStatus"], "outputs": {item["OutputKey"]: item.get("OutputValue", "") for item in stack.get("Outputs", [])}, }