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(apigateway-v1): add GetUsagePlanKey handler (#556)
marcin-nowak-scl8cd3687475b0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6b423b21..8f986fc6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,13 @@ Versioning follows [Semantic Versioning](https://semver.org/).---+## [Unreleased]++### Fixed+- **API Gateway v1 `GetUsagePlanKey` per-key read handler** — `GET /usageplans/{planId}/keys/{keyId}` was missing from the route dispatcher; only list/create/delete were registered, so the per-key path fell through to a 404. Terraform's AWS provider invokes `GetUsagePlanKey` immediately after `CreateUsagePlanKey` to confirm the resource exists, and the missing handler caused `aws_api_gateway_usage_plan_key` applies to abort with `reading API Gateway Usage Plan Key (...): couldn't find resource`. Added `_get_usage_plan_key(plan_id, key_id)` returning the stored entry on hit and `NotFoundException` on miss for either the plan id or the key id. Contributed by @marcin-nowak-scl.++---+## [1.3.26] — 2026-05-04### Addeddiff --git a/ministack/services/apigateway_v1.py b/ministack/services/apigateway_v1.pyindex fda71344..5fb4a3bc 100644--- a/ministack/services/apigateway_v1.py+++ b/ministack/services/apigateway_v1.py@@ -652,6 +652,8 @@ async def handle_request(method, path, headers, body, query_params):if method == "POST":return _create_usage_plan_key(plan_id, data)else:+ if method == "GET":+ return _get_usage_plan_key(plan_id, sub_id)if method == "DELETE":return _delete_usage_plan_key(plan_id, sub_id)else:@@ -1762,6 +1764,15 @@ def _get_usage_plan_keys(plan_id, query_params):return _v1_paginated_response(list(_usage_plan_keys.get(plan_id, {}).values()), query_params)+def _get_usage_plan_key(plan_id, key_id):+ if plan_id not in _usage_plans:+ return _v1_error("NotFoundException", "Invalid Usage Plan identifier specified", 404)+ plan_key = _usage_plan_keys.get(plan_id, {}).get(key_id)+ if not plan_key:+ return _v1_error("NotFoundException", "Invalid Usage Plan Key identifier specified", 404)+ return _v1_response(plan_key, 200)++def _delete_usage_plan_key(plan_id, key_id):if plan_id not in _usage_plans:return _v1_error("NotFoundException", "Invalid Usage Plan identifier specified", 404)diff --git a/tests/test_apigatewayv1.py b/tests/test_apigatewayv1.pyindex c190c7f1..3210ff12 100644--- a/tests/test_apigatewayv1.py+++ b/tests/test_apigatewayv1.py@@ -1225,6 +1225,34 @@ def test_apigwv1_usage_plan_key_crud(apigw_v1):keys2 = apigw_v1.get_usage_plan_keys(usagePlanId=plan_id)["items"]assert not any(k["id"] == key_id for k in keys2)+def test_apigwv1_get_usage_plan_key(apigw_v1):+ """GetUsagePlanKey returns the per-key entry. The Terraform AWS provider+ issues this call immediately after CreateUsagePlanKey to verify the+ resource exists; before the handler was added the request fell through+ to a 404 and aws_api_gateway_usage_plan_key applies aborted with+ 'couldn't find resource'."""+ api_key = apigw_v1.create_api_key(name="qa-v1-gupk-key", enabled=True)+ key_id = api_key["id"]+ plan_id = apigw_v1.create_usage_plan(+ name="qa-v1-gupk-plan",+ throttle={"rateLimit": 100, "burstLimit": 200},+ )["id"]+ apigw_v1.create_usage_plan_key(usagePlanId=plan_id, keyId=key_id, keyType="API_KEY")++ got = apigw_v1.get_usage_plan_key(usagePlanId=plan_id, keyId=key_id)+ assert got["id"] == key_id+ assert got["type"] == "API_KEY"++ with pytest.raises(ClientError) as exc:+ apigw_v1.get_usage_plan_key(usagePlanId=plan_id, keyId="missing-key-id")+ assert exc.value.response["Error"]["Code"] == "NotFoundException"++ with pytest.raises(ClientError) as exc:+ apigw_v1.get_usage_plan_key(usagePlanId="missing-plan-id", keyId=key_id)+ assert exc.value.response["Error"]["Code"] == "NotFoundException"++ apigw_v1.delete_usage_plan_key(usagePlanId=plan_id, keyId=key_id)+def test_apigwv1_created_date_is_unix_timestamp(apigw_v1):resp = apigw_v1.create_rest_api(name="tf-date-test")created = resp["createdDate"]