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
feat(cfn): Add account in api gateway (#658)
Nahuel Nucera8e5095d08265
diff --git a/ministack/services/cloudformation/provisioners.py b/ministack/services/cloudformation/provisioners.pyindex 6b5f97d4..bda26d17 100644--- a/ministack/services/cloudformation/provisioners.py+++ b/ministack/services/cloudformation/provisioners.py@@ -1269,6 +1269,29 @@ def _apigw_stage_delete(physical_id, props):_apigw_v1._delete_stage(api_id, stage_name)+def _apigw_account_create(logical_id, props, stack_name):+ """``AWS::ApiGateway::Account`` is a singleton per AWS account storing the+ IAM role API Gateway uses to push logs to CloudWatch. CDK's+ ``RestApi({ cloudWatchRole: true })`` generates this automatically.++ We persist ``CloudWatchRoleArn`` into the same store the runtime+ ``UpdateAccount`` API writes to, so a subsequent ``GetAccount`` call+ round-trips the value. No real side effect — the role isn't used.+ """+ role_arn = props.get("CloudWatchRoleArn")+ settings = dict(_apigw_v1._account_settings.get("settings") or {})+ if role_arn is not None:+ settings["cloudwatchRoleArn"] = role_arn+ _apigw_v1._account_settings["settings"] = settings+ return logical_id, {}+++def _apigw_account_delete(physical_id, props):+ settings = dict(_apigw_v1._account_settings.get("settings") or {})+ settings.pop("cloudwatchRoleArn", None)+ _apigw_v1._account_settings["settings"] = settings++# --- Lambda EventSourceMapping ---def _lambda_esm_create(logical_id, props, stack_name):@@ -3577,6 +3600,7 @@ _RESOURCE_HANDLERS = {"AWS::ApiGateway::Authorizer": {"create": _apigw_authorizer_create, "delete": _apigw_authorizer_delete},"AWS::ApiGateway::Deployment": {"create": _apigw_deployment_create, "delete": _apigw_deployment_delete},"AWS::ApiGateway::Stage": {"create": _apigw_stage_create, "delete": _apigw_stage_delete},+ "AWS::ApiGateway::Account": {"create": _apigw_account_create, "delete": _apigw_account_delete},"AWS::Lambda::EventSourceMapping": {"create": _lambda_esm_create, "delete": _lambda_esm_delete},"AWS::Pipes::Pipe": {"create": _pipes_pipe_create, "delete": _pipes_pipe_delete},"AWS::Lambda::Alias": {"create": _lambda_alias_create, "delete": _lambda_alias_delete},diff --git a/tests/test_cfn.py b/tests/test_cfn.pyindex 1d272975..d43b39af 100644--- a/tests/test_cfn.py+++ b/tests/test_cfn.py@@ -3056,3 +3056,32 @@ def test_cfn_apigateway_authorizer_provisions(cfn):cfn.delete_stack(StackName=stack_name)_wait_stack(cfn, stack_name)+++def test_cfn_apigateway_account_provisions(cfn, apigw_v1):+ """AWS::ApiGateway::Account is the CDK ``cloudWatchRole: true`` resource.+ Without a registered handler, stacks fail with ``Unsupported resource+ type: AWS::ApiGateway::Account``. We persist the CloudWatchRoleArn into+ the same store the runtime GetAccount API reads from, so the value round-+ trips end-to-end. Regression for issue #657.+ """+ stack_name = f"intg-cfn-apigw-account-{_uuid_mod.uuid4().hex[:8]}"+ role_arn = f"arn:aws:iam::000000000000:role/cfn-apigw-cw-{_uuid_mod.uuid4().hex[:6]}"+ template = {+ "Resources": {+ "Account": {+ "Type": "AWS::ApiGateway::Account",+ "Properties": {"CloudWatchRoleArn": role_arn},+ },+ },+ }+ cfn.create_stack(StackName=stack_name, TemplateBody=json.dumps(template))+ stack = _wait_stack(cfn, stack_name)+ assert stack["StackStatus"] == "CREATE_COMPLETE"++ # GetAccount must reflect the role arn the stack just set.+ settings = apigw_v1.get_account()+ assert settings.get("cloudwatchRoleArn") == role_arn++ cfn.delete_stack(StackName=stack_name)+ _wait_stack(cfn, stack_name)