Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
Fix API Gateway stage Ref value (#1162)
robert-pitt-foodhubb1da2b2d1e8b
diff --git a/ministack/services/cloudformation/provisioners.py b/ministack/services/cloudformation/provisioners.pyindex c136376d..2900c9cf 100644--- a/ministack/services/cloudformation/provisioners.py+++ b/ministack/services/cloudformation/provisioners.py@@ -2079,8 +2079,9 @@ def _apigw_stage_create(logical_id, props, stack_name):"tags": {t["Key"]: t["Value"] for t in props.get("Tags", [])},}_apigw_v1._create_stage(api_id, data)- pid = f"{api_id}-{stage_name}"- return pid, {"StageName": stage_name}+ # AWS::ApiGateway::Stage Ref returns the stage name. The physical ID feeds+ # MiniStack's generic Ref resolver, so it must not include the REST API ID.+ return stage_name, {"StageName": stage_name}def _apigw_stage_delete(physical_id, props):diff --git a/tests/test_cfn.py b/tests/test_cfn.pyindex 59ae2730..b10ec050 100644--- a/tests/test_cfn.py+++ b/tests/test_cfn.py@@ -4431,6 +4431,58 @@ def test_cfn_apigateway_account_provisions(cfn, apigw_v1):_wait_stack(cfn, stack_name)+def test_cfn_apigateway_stage_ref_returns_stage_name(cfn, apigw_v1):+ """Stage Ref is directly usable as the stageName in API Gateway calls.++ Regression for #1161: MiniStack previously returned ``<api-id>-<stage>``+ from Ref, causing dependent custom resources to fail GetStage with+ ``Invalid Stage identifier specified``.+ """+ suffix = _uuid_mod.uuid4().hex[:8]+ stack_name = f"intg-cfn-apigw-stage-ref-{suffix}"+ stage_name = "prod"+ template = {+ "Resources": {+ "Api": {+ "Type": "AWS::ApiGateway::RestApi",+ "Properties": {"Name": f"stage-ref-{suffix}"},+ },+ "Deployment": {+ "Type": "AWS::ApiGateway::Deployment",+ "Properties": {"RestApiId": {"Ref": "Api"}},+ },+ "Stage": {+ "Type": "AWS::ApiGateway::Stage",+ "Properties": {+ "RestApiId": {"Ref": "Api"},+ "DeploymentId": {"Ref": "Deployment"},+ "StageName": stage_name,+ },+ },+ },+ "Outputs": {+ "ApiId": {"Value": {"Ref": "Api"}},+ "StageName": {"Value": {"Ref": "Stage"}},+ },+ }++ cfn.create_stack(StackName=stack_name, TemplateBody=json.dumps(template))+ stack = _wait_stack(cfn, stack_name)+ assert stack["StackStatus"] == "CREATE_COMPLETE", stack.get("StackStatusReason")++ outputs = {item["OutputKey"]: item["OutputValue"] for item in stack.get("Outputs", [])}+ assert outputs["StageName"] == stage_name++ stage = apigw_v1.get_stage(+ restApiId=outputs["ApiId"],+ stageName=outputs["StageName"],+ )+ assert stage["stageName"] == stage_name++ cfn.delete_stack(StackName=stack_name)+ _wait_stack(cfn, stack_name)++def test_cfn_apigateway_domain_name_lifecycle(cfn, apigw_v1):"""CloudFormation provisions CDK-style regional and edge custom domains."""suffix = _uuid_mod.uuid4().hex[:8]