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
release v1.3.20 (#529)
Nahuel Nuceradf5a7c952ee4
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b031f99e..a9e0bce2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,13 +7,19 @@ Versioning follows [Semantic Versioning](https://semver.org/).----## [Unreleased]+## [1.3.20] — 2026-04-29### Added-- **API Gateway (HTTP API and REST): JWT authorizers, HTTP proxy integrations, and non-blocking I/O** — HTTP API (`apigateway`) and REST API (`apigateway_v1`): enforce JWT `issuer` + `audience` validation against a JWKS URL, request/response **parameter mapping** for `HTTP` / `HTTP_PROXY` integrations, and `ministack.core.nonblocking_http` so upstream proxy and JWKS work does not block the event loop. Operator tuning: `MINISTACK_APIGW_PROXY_TIMEOUT_SECONDS` (default `30`), `MINISTACK_APIGW_JWKS_TIMEOUT_SECONDS` (default `5`).-- **DynamoDB Streams read API** — new `ministack/services/dynamodb_streams.py` exposes `ListStreams`, `DescribeStream`, `GetShardIterator`, and `GetRecords` via `boto3.client("dynamodbstreams")` and the `streams.dynamodb.*` host. Reads the records already captured by the main DynamoDB service (emitted from `PutItem`, `UpdateItem`, `DeleteItem`, `TransactWriteItems`, and `BatchWriteItem`) so the public Streams API and the internal Lambda ESM path share one source of truth. Supports all four iterator types (`TRIM_HORIZON`, `LATEST`, `AT_SEQUENCE_NUMBER`, `AFTER_SEQUENCE_NUMBER`) and all four stream view types (`NEW_AND_OLD_IMAGES`, `NEW_IMAGE`, `OLD_IMAGE`, `KEYS_ONLY`). Single synthetic shard per stream; opaque base64 iterator tokens. Unblocks `DynamoDbOutboxWorker`-style consumers.-- **DynamoDB → Kinesis streaming destination** — `EnableKinesisStreamingDestination`, `DisableKinesisStreamingDestination`, `DescribeKinesisStreamingDestination`, and `UpdateKinesisStreamingDestination` on `boto3.client("dynamodb")`. Item mutations from `PutItem` / `UpdateItem` / `DeleteItem` / `TransactWriteItems` / `BatchWriteItem` fan out to every ACTIVE destination as JSON-encoded records (via `kinesis.put_record_internal`) for Kinesis / Lambda ESM / Firehose-style consumers. DISABLED destinations remain on `Describe` for the ~24h AWS window; `DeleteTable` drops destinations. Coverage: `tests/test_dynamodb_kinesis_destination.py`.-- **Native HTTPS via `USE_SSL=1`** — the gateway listener now speaks TLS when `USE_SSL=1` (also accepts `true` / `yes`). Drop-in compatible with LocalStack's `USE_SSL=true`, so a `compose.yml` switching from LocalStack to MiniStack doesn't need TLS-specific changes. By default, MiniStack auto-generates a self-signed RSA cert (CN: `ministack-local`, SAN: `localhost`, `ministack`, `127.0.0.1`, `::1`) cached under `${TMPDIR}/ministack-tls/` so the cert survives restarts. To pin a specific cert (e.g. an `mkcert`-issued one for browser trust), set `MINISTACK_SSL_CERT` and `MINISTACK_SSL_KEY` to PEM paths. Auto-generation uses the `cryptography` package (already shipped in both the regular and `:full` images). Unblocks AWS SDKs that hardcode `https://` against Cognito Hosted UI endpoints (e.g. Amplify v6) without needing a separate TLS-terminating proxy. Closes #526.+- **API Gateway (HTTP API and REST): JWT authorizer enforcement, HTTP proxy parameter mapping, and non-blocking proxy/JWKS I/O** — HTTP API (`apigateway`) and REST API (`apigateway_v1`) now enforce JWT `issuer` + `audience` validation against a JWKS URL (RS256 signatures only — Cognito's standard), apply request **parameter mappings** for `HTTP` / `HTTP_PROXY` integrations (`append`/`overwrite`/`remove` for headers and querystring, plus `overwrite:path`, with `$context.authorizer.jwt.claims.*` and `$stageVariables.*` substitution), and offload upstream proxy + JWKS fetches off the event loop so a slow backend can no longer stall unrelated requests. Authorizer issuers of the form `https://cognito-idp.{region}.amazonaws.com/{poolId}` are rewritten to MiniStack's local Cognito JWKS endpoint so locally-minted tokens verify without leaving the box. Reserved-header list for parameter mapping matches the AWS HTTP API spec exactly. Operator tuning: `MINISTACK_APIGW_PROXY_TIMEOUT_SECONDS` (default `30`), `MINISTACK_APIGW_JWKS_TIMEOUT_SECONDS` (default `5`). Cognito's signing key is now persisted under `${STATE_DIR}/cognito-rsa-key.pem` so tokens minted in one process verify in another. Contributed by @marcin-nowak-scl.+- **DynamoDB Streams read API** — new `ministack/services/dynamodb_streams.py` exposes `ListStreams`, `DescribeStream`, `GetShardIterator`, and `GetRecords` via `boto3.client("dynamodbstreams")` and the `streams.dynamodb.*` host. Reads the records already captured by the main DynamoDB service (emitted from `PutItem`, `UpdateItem`, `DeleteItem`, `TransactWriteItems`, and `BatchWriteItem`) so the public Streams API and the internal Lambda ESM path share one source of truth. Supports all four iterator types (`TRIM_HORIZON`, `LATEST`, `AT_SEQUENCE_NUMBER`, `AFTER_SEQUENCE_NUMBER`) and all four stream view types (`NEW_AND_OLD_IMAGES`, `NEW_IMAGE`, `OLD_IMAGE`, `KEYS_ONLY`). Single synthetic shard per stream; opaque base64 iterator tokens. Unblocks `DynamoDbOutboxWorker`-style consumers. Contributed by @marcin-nowak-scl.+- **DynamoDB → Kinesis streaming destination** — `EnableKinesisStreamingDestination`, `DisableKinesisStreamingDestination`, `DescribeKinesisStreamingDestination`, and `UpdateKinesisStreamingDestination` on `boto3.client("dynamodb")`. Item mutations from `PutItem` / `UpdateItem` / `DeleteItem` / `TransactWriteItems` / `BatchWriteItem` fan out to every ACTIVE destination as JSON-encoded records (via `kinesis.put_record_internal`) for Kinesis / Lambda ESM / Firehose-style consumers. DISABLED destinations remain on `Describe` for the ~24h AWS window; `DeleteTable` drops destinations. The wire envelope reuses the DynamoDB Streams record shape — AWS does not publicly document the exact Kinesis envelope it produces, so MiniStack approximates it with the Streams record. Contributed by @marcin-nowak-scl.+- **Native HTTPS via `USE_SSL=1`** — the gateway listener now speaks TLS when `USE_SSL=1` (also accepts `true` / `yes`), aligning with LocalStack's `USE_SSL` flag name so a `compose.yml` switching emulator doesn't need TLS-specific changes. By default, MiniStack auto-generates a self-signed RSA cert (CN: `ministack-local`, SAN: `localhost`, `ministack`, `127.0.0.1`, `::1`) cached under `${TMPDIR}/ministack-tls/` so the cert survives restarts. To pin a specific cert (e.g. an `mkcert`-issued one for browser trust), set `MINISTACK_SSL_CERT` and `MINISTACK_SSL_KEY` to PEM paths. Auto-generation shells out to the `openssl` CLI (already present in both images), so no Python crypto dep is added. Unblocks AWS SDKs that hardcode `https://` against Cognito Hosted UI endpoints (e.g. Amplify v6) without needing a separate TLS-terminating proxy. Closes #526. Contributed by @prandogabriel.++### Fixed+- **Step Functions `aws-sdk:rds:removeFromGlobalCluster` left global cluster members attached** — query-protocol parameter conversion uppercased `DbClusterIdentifier` to `DBClusterIdentifier`, but the RDS API shape for `RemoveFromGlobalCluster` intentionally uses `DbClusterIdentifier`. The task now preserves that member name so a successful remove actually detaches the cluster and a following `DeleteGlobalCluster` matches AWS behavior. Contributed by @jayjanssen.+- **Kinesis `ListShards` `NextToken` returned a raw shard ID instead of an opaque pagination token** — AWS specifies an opaque token (length 1-1048576) with a 300-second TTL that yields `ExpiredNextTokenException` when expired. MiniStack now emits a base64url-encoded opaque token and rejects expired or malformed tokens with the AWS-correct error code, so SDKs that round-trip the token (and the rare consumers that inspect or persist it) see AWS-shape behavior.+- **DynamoDB `DescribeContinuousBackups` returned `EarliestRestorableDateTime: 0` / `LatestRestorableDateTime: 0` when PITR was disabled** — emitting Unix epoch 1970 misled SDK consumers that parsed the values into datetimes. Both fields are now omitted when `PointInTimeRecoveryStatus` is `DISABLED` and populated with a real timestamp when `ENABLED`.+- **DynamoDB `DescribeEndpoints` returned the hardcoded real-AWS endpoint `dynamodb.us-east-1.amazonaws.com`** — endpoint-discovery-aware SDKs would cache that address and silently redirect subsequent calls AWAY from MiniStack to real AWS. The endpoint now reflects MiniStack's own host (`MINISTACK_HOST`:`GATEWAY_PORT`) so SDKs keep talking to the emulator.---@@ -23,7 +29,6 @@ Versioning follows [Semantic Versioning](https://semver.org/).- **S3 virtual-hosted and path-style integration tests** — `TestS3VhostGetPutObject` exercises both addressing styles end-to-end (simple and max-length dotted bucket names), `TestExtractS3VhostBucket` unit-tests the vhost extraction function, and `patch_endpoint_dns` lets virtual-hosted requests resolve against localhost in CI. `make_client` now accepts `additional_config_kwargs` for per-test SDK config overrides. Contributed by @mgius-ae.### Fixed-- **Step Functions `aws-sdk:rds:removeFromGlobalCluster` left global cluster members attached** — query-protocol parameter conversion uppercased `DbClusterIdentifier` to `DBClusterIdentifier`, but the RDS API shape for `RemoveFromGlobalCluster` intentionally uses `DbClusterIdentifier`. The task now preserves that member name so a successful remove actually detaches the cluster and a following `DeleteGlobalCluster` matches AWS behavior.- **S3 requests via custom `MINISTACK_HOST` hostname returned `NoSuchBucket`** — `_extract_s3_vhost_bucket` (introduced in 1.3.17) treated any dotted hostname as a virtual-hosted S3 URL, extracting the first label as a bucket name. Requests to `http://aws.private:4566` were misrouted as a vhost request for a bucket named `aws`. The function now checks the tail against `MINISTACK_HOST` and recognises all 18 documented AWS S3 virtual-hosted patterns (`s3`, `s3-accelerate`, `s3-fips`, `s3-accesspoint`, `s3-accesspoint-fips`, `s3-website`, `s3express-*`, and their dualstack/regional variants). Bare hostnames, IPv4 addresses, and `localhost` are correctly treated as path-style. Reported by @dsrosario.- **Glue `GetDatabase` returned `LocationUri: ""` when not set** — AWS specifies a minimum length of 1 for `LocationUri`, so the empty-string default violated the spec. Now returns `null` when the field is omitted from `CreateDatabase`. Contributed by @dcrn.- **Ruff linter not running on pull requests** — CI workflow trigger was missing the PR event.diff --git a/Dockerfile b/Dockerfileindex 47afe509..5e1a28ef 100644--- a/Dockerfile+++ b/Dockerfile@@ -67,8 +67,8 @@ ENV MINISTACK_VERSION=${MINISTACK_VERSION} \EXPOSE 4566 2222-# Pure Python healthcheck — honours USE_SSL so it works for both HTTP and HTTPS.+# Pure Python healthcheck — no curl dependency; USE_SSL for HTTP/HTTPS.HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \- CMD python -c "import os,ssl,urllib.request as r; t=os.environ.get('USE_SSL','').strip().lower() in ('1','true','yes'); r.urlopen(('https' if t else 'http')+'://localhost:'+os.environ.get('GATEWAY_PORT','4566')+'/_ministack/health',context=ssl._create_unverified_context() if t else None)" || exit 1+ CMD python -c "import os,ssl,urllib.request as r; t=os.environ.get('USE_SSL','').strip().lower() in ('1','true','yes'); r.urlopen(('https' if t else 'http')+'://localhost:4566/_ministack/health',context=ssl._create_unverified_context() if t else None)" || exit 1ENTRYPOINT ["python", "-m", "hypercorn", "ministack.app:app", "-c", "file:ministack/core/hypercorn_conf.py", "--bind", "0.0.0.0:4566", "--keep-alive", "75"]diff --git a/Dockerfile.full b/Dockerfile.fullindex 2fb71040..8377dc30 100644--- a/Dockerfile.full+++ b/Dockerfile.full@@ -82,8 +82,8 @@ ENV MINISTACK_VERSION=${MINISTACK_VERSION} \EXPOSE 4566 2222-# Pure Python healthcheck — honours USE_SSL so it works for both HTTP and HTTPS.+# Pure Python healthcheck — no curl dependency; USE_SSL for HTTP/HTTPS.HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \- CMD python -c "import os,ssl,urllib.request as r; t=os.environ.get('USE_SSL','').strip().lower() in ('1','true','yes'); r.urlopen(('https' if t else 'http')+'://localhost:'+os.environ.get('GATEWAY_PORT','4566')+'/_ministack/health',context=ssl._create_unverified_context() if t else None)" || exit 1+ CMD python -c "import os,ssl,urllib.request as r; t=os.environ.get('USE_SSL','').strip().lower() in ('1','true','yes'); r.urlopen(('https' if t else 'http')+'://localhost:4566/_ministack/health',context=ssl._create_unverified_context() if t else None)" || exit 1ENTRYPOINT ["python", "-m", "hypercorn", "ministack.app:app", "-c", "file:ministack/core/hypercorn_conf.py", "--bind", "0.0.0.0:4566", "--keep-alive", "75"]diff --git a/README.md b/README.mdindex df11506b..8935e078 100644--- a/README.md+++ b/README.md@@ -660,6 +660,9 @@ ecs.stop_task(cluster="dev", task=task_arn)| `SMTP_HOST` | _(unset)_ | SMTP server for SES email relay (e.g. `mailhog:1025`). When set, SES SendEmail/SendRawEmail actually deliver mail. When unset, emails are stored in-memory only || `MINISTACK_APIGW_PROXY_TIMEOUT_SECONDS` | `30` | API Gateway v1/v2 HTTP `HTTP_PROXY` / `HTTP` integration: upstream request timeout (seconds) || `MINISTACK_APIGW_JWKS_TIMEOUT_SECONDS` | `5` | API Gateway v2 JWT authorizer: JWKS document fetch timeout (seconds) |+| `USE_SSL` | `0` | Enable HTTPS on the gateway listener. Accepts `1`, `true`, `yes`. LocalStack-compatible flag name |+| `MINISTACK_SSL_CERT` | _(unset)_ | Optional PEM-encoded server certificate path; required together with `MINISTACK_SSL_KEY`. When unset, MiniStack auto-generates a self-signed cert under `${TMPDIR}/ministack-tls/` (cached across restarts) |+| `MINISTACK_SSL_KEY` | _(unset)_ | Optional PEM-encoded private key path; required together with `MINISTACK_SSL_CERT` |### API Gateway HTTP proxy execution modeldiff --git a/ministack/core/nonblocking_http.py b/ministack/core/nonblocking_http.pydeleted file mode 100644index a1193827..00000000--- a/ministack/core/nonblocking_http.py+++ /dev/null@@ -1,23 +0,0 @@-import asyncio-import os-import urllib.request---def timeout_from_env(env_name: str, default_seconds: float) -> float:- raw = os.environ.get(env_name)- if raw is None:- return float(default_seconds)- try:- parsed = float(raw)- except ValueError:- return float(default_seconds)- return parsed if parsed > 0 else float(default_seconds)---def _urlopen_sync(request_or_url, timeout_seconds: float):- with urllib.request.urlopen(request_or_url, timeout=timeout_seconds) as resp:- return resp.status, dict(resp.headers.items()), resp.read()---async def urlopen(request_or_url, timeout_seconds: float):- return await asyncio.to_thread(_urlopen_sync, request_or_url, timeout_seconds)diff --git a/ministack/core/router.py b/ministack/core/router.pyindex 0cdadd05..cf56e14b 100644--- a/ministack/core/router.py+++ b/ministack/core/router.py@@ -38,11 +38,14 @@ SERVICE_PATTERNS = {"host_patterns": [r"sns\."],"target_prefixes": ["AmazonSNS"],},- # NOTE: dynamodbstreams must be listed BEFORE dynamodb because the target- # prefix "DynamoDBStreams_20120810" also starts with "DynamoDB_20120810",- # and detect_service() checks target_prefixes in iteration order with- # str.startswith(). Without this order, Streams traffic would be misrouted- # to the main DynamoDB service.+ # NOTE: dynamodbstreams must be listed BEFORE dynamodb because the host+ # `streams.dynamodb.{region}.amazonaws.com` matches both `streams\.dynamodb\.`+ # and `dynamodb\.` regexes — when a request lacks an X-Amz-Target header+ # and falls through to host-pattern matching, detect_service() iterates in+ # dict order and the first hit wins. Without this order, Streams traffic+ # via host would be misrouted to the main DynamoDB service. (Target-prefix+ # routing is unambiguous between the two: `DynamoDBStreams_20120810` and+ # `DynamoDB_20120810` diverge at index 8.)"dynamodbstreams": {"target_prefixes": ["DynamoDBStreams_20120810"],"host_patterns": [r"streams\.dynamodb\."],diff --git a/ministack/services/apigateway.py b/ministack/services/apigateway.pyindex 3121b4e0..acffa65c 100644--- a/ministack/services/apigateway.py+++ b/ministack/services/apigateway.py@@ -51,17 +51,42 @@ import urllib.errorimport urllib.parseimport urllib.request-from ministack.core.nonblocking_http import timeout_from_env, urlopen as nb_urlopen-from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, new_uuid, get_region+from ministack.core.responses import AccountScopedDict, error_response_json, get_account_id, get_region, new_uuid_HOST = os.environ.get("MINISTACK_HOST", "localhost")_PORT = os.environ.get("GATEWAY_PORT", "4566")logger = logging.getLogger("apigateway")++def _timeout_from_env(env_name: str, default_seconds: float) -> float:+ """Read a positive float timeout from an env var; fall back on missing /+ non-numeric / non-positive values."""+ raw = os.environ.get(env_name)+ if raw is None:+ return float(default_seconds)+ try:+ parsed = float(raw)+ except ValueError:+ return float(default_seconds)+ return parsed if parsed > 0 else float(default_seconds)+++def _urlopen_sync(request_or_url, timeout_seconds: float):+ with urllib.request.urlopen(request_or_url, timeout=timeout_seconds) as resp:+ return resp.status, dict(resp.headers.items()), resp.read()+++async def _urlopen_async(request_or_url, timeout_seconds: float):+ """Run a blocking ``urllib`` call on the default thread executor so the+ ASGI event loop stays responsive while upstream / JWKS sockets are in+ flight. Used by the JWKS fetcher and the HTTP_PROXY integration."""+ return await asyncio.to_thread(_urlopen_sync, request_or_url, timeout_seconds)++REGION = os.environ.get("MINISTACK_REGION", "us-east-1")-_PROXY_TIMEOUT_SECONDS = timeout_from_env("MINISTACK_APIGW_PROXY_TIMEOUT_SECONDS", 30.0)-_JWKS_TIMEOUT_SECONDS = timeout_from_env("MINISTACK_APIGW_JWKS_TIMEOUT_SECONDS", 5.0)+_PROXY_TIMEOUT_SECONDS = _timeout_from_env("MINISTACK_APIGW_PROXY_TIMEOUT_SECONDS", 30.0)+_JWKS_TIMEOUT_SECONDS = _timeout_from_env("MINISTACK_APIGW_JWKS_TIMEOUT_SECONDS", 5.0)# ---- Module-level state ----_apis = AccountScopedDict() # api_id -> api object@@ -73,7 +98,10 @@ _authorizers = AccountScopedDict() # api_id -> {authorizer_id -> authorizer ob_api_tags = AccountScopedDict() # resource_arn -> {key -> value}_route_responses = AccountScopedDict() # api_id -> {route_id -> {rr_id -> route_response}}_integration_responses = AccountScopedDict() # api_id -> {integration_id -> {ir_id -> int_response}}-_jwks_cache: dict = {}+# JWKS cache is account-scoped because issuer URLs in MiniStack can resolve+# to per-account local Cognito user pools — the same URL string may legitimately+# serve different keys in different accounts.+_jwks_cache = AccountScopedDict()# WebSocket connection registry — connections are not per-account-scoped at the store level# because the @connections management API may arrive on any host/account; instead we store@@ -82,6 +110,10 @@ _jwks_cache: dict = {}# close_event (asyncio.Event), lastActiveAt, identity} }_ws_connections: dict = {}+# HTTP API parameter-mapping reserved headers — sourced from+# https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-parameter-mapping.html+# (verified 2026-04-29). Any change to this list must be cross-checked+# against that AWS doc page; do not extend by guesswork._RESERVED_HEADER_EXACT = {"authorization","connection",@@ -478,7 +510,7 @@ async def _fetch_jwks(url: str) -> dict:now = time.time()if cached and cached.get("expiresAt", 0) > now:return cached["jwks"]- _, _, body = await nb_urlopen(url, _JWKS_TIMEOUT_SECONDS)+ _, _, body = await _urlopen_async(url, _JWKS_TIMEOUT_SECONDS)payload = json.loads(body or b"{}")_jwks_cache[url] = {"jwks": payload,@@ -1003,7 +1035,7 @@ async def _invoke_http_proxy(integration, path, method, headers, body, query_parif k.lower() not in ("host", "content-length"):req.add_header(k, v)try:- status, resp_headers_raw, resp_body = await nb_urlopen(req, _PROXY_TIMEOUT_SECONDS)+ status, resp_headers_raw, resp_body = await _urlopen_async(req, _PROXY_TIMEOUT_SECONDS)resp_headers = {"Content-Type": resp_headers_raw.get("Content-Type", "application/json")}return status, resp_headers, resp_bodyexcept urllib.error.HTTPError as e:diff --git a/ministack/services/apigateway_v1.py b/ministack/services/apigateway_v1.pyindex cf96f8f5..809998e8 100644--- a/ministack/services/apigateway_v1.py+++ b/ministack/services/apigateway_v1.py@@ -77,8 +77,8 @@ import timeimport urllib.errorimport urllib.request-from ministack.core.nonblocking_http import timeout_from_env, urlopen as nb_urlopen-from ministack.core.responses import AccountScopedDict, get_account_id, new_uuid, get_region+from ministack.core.responses import AccountScopedDict, get_account_id, get_region, new_uuid+from ministack.services.apigateway import _timeout_from_env, _urlopen_asyncdef _now_unix():@@ -88,7 +88,7 @@ def _now_unix():return int(time.time())logger = logging.getLogger("apigateway_v1")-_PROXY_TIMEOUT_SECONDS = timeout_from_env("MINISTACK_APIGW_PROXY_TIMEOUT_SECONDS", 30.0)+_PROXY_TIMEOUT_SECONDS = _timeout_from_env("MINISTACK_APIGW_PROXY_TIMEOUT_SECONDS", 30.0)REGION = os.environ.get("MINISTACK_REGION", "us-east-1")@@ -920,7 +920,7 @@ async def _invoke_http_proxy_v1(integration, path, method, headers, body, query_if k.lower() not in ("host", "content-length"):req.add_header(k, v)try:- status, resp_headers_raw, resp_body = await nb_urlopen(req, _PROXY_TIMEOUT_SECONDS)+ status, resp_headers_raw, resp_body = await _urlopen_async(req, _PROXY_TIMEOUT_SECONDS)resp_headers = {"Content-Type": resp_headers_raw.get("Content-Type", "application/json")}return status, resp_headers, resp_bodyexcept urllib.error.HTTPError as e:diff --git a/ministack/services/dynamodb.py b/ministack/services/dynamodb.pyindex 4ae34c63..990428c2 100644--- a/ministack/services/dynamodb.py+++ b/ministack/services/dynamodb.py@@ -106,16 +106,9 @@ def _next_stream_seq():return f"{int(time.time() * 1000):020d}{_stream_seq_counter:010d}"-def _emit_stream_event(table_name: str, event_name: str, old_item: dict | None, new_item: dict | None):- """Emit a DynamoDB Streams record if the table has StreamSpecification enabled."""- table = _tables.get(table_name)- if not table:- return- spec = table.get("StreamSpecification")- if not spec or not spec.get("StreamEnabled"):- return-- view_type = spec.get("StreamViewType", "NEW_AND_OLD_IMAGES")+def _build_change_record(table: dict, event_name: str, old_item: dict | None, new_item: dict | None, view_type: str) -> dict:+ """Build a DynamoDB Streams-shaped change record. ``view_type`` controls+ whether OldImage / NewImage are populated."""record: dict = {"eventID": new_uuid(),"eventName": event_name,@@ -145,11 +138,41 @@ def _emit_stream_event(table_name: str, event_name: str, old_item: dict | None,if view_type in ("NEW_AND_OLD_IMAGES", "NEW_IMAGE") and new_item:record["dynamodb"]["NewImage"] = new_item- if table_name not in _stream_records:- _stream_records[table_name] = []- _stream_records[table_name].append(record)+ return record+++def _emit_stream_event(table_name: str, event_name: str, old_item: dict | None, new_item: dict | None):+ """Emit a change to DynamoDB Streams (if enabled) and to any ACTIVE Kinesis+ streaming destinations registered for this table.++ AWS treats DynamoDB Streams and Kinesis streaming destination as+ independent subscriptions — a table can have either, both, or neither.+ Each path is gated independently here; the function name is kept for+ backwards compatibility with existing call sites."""+ table = _tables.get(table_name)+ if not table:+ return++ spec = table.get("StreamSpecification") or {}+ streams_enabled = bool(spec.get("StreamEnabled"))+ has_kinesis = bool(_kinesis_destinations.get(table_name))+ if not streams_enabled and not has_kinesis:+ return++ if streams_enabled:+ view_type = spec.get("StreamViewType", "NEW_AND_OLD_IMAGES")+ record = _build_change_record(table, event_name, old_item, new_item, view_type)+ if table_name not in _stream_records:+ _stream_records[table_name] = []+ _stream_records[table_name].append(record)- _fan_out_to_kinesis(table_name, record)+ if has_kinesis:+ # AWS's Kinesis streaming destination always carries the equivalent of+ # NEW_AND_OLD_IMAGES — the StreamViewType setting belongs to Streams,+ # not to the Kinesis fan-out path. Build a fresh record so its+ # SequenceNumber and eventID are independent of the Streams record.+ kinesis_record = _build_change_record(table, event_name, old_item, new_item, "NEW_AND_OLD_IMAGES")+ _fan_out_to_kinesis(table_name, kinesis_record)def _fan_out_to_kinesis(table_name: str, record: dict) -> None:@@ -1342,14 +1365,20 @@ def _describe_continuous_backups(data):if name not in _tables:return error_response_json("ResourceNotFoundException", f"Table {name} not found", 400)pitr_enabled = _pitr_settings.get(name, False)+ pitr_desc: dict = {+ "PointInTimeRecoveryStatus": "ENABLED" if pitr_enabled else "DISABLED",+ }+ # AWS only meaningfully populates the restorable-date-time fields when PITR+ # is enabled; emitting `0` (Unix epoch 1970) misleads SDK consumers that+ # parse them into datetimes. Omit when disabled.+ if pitr_enabled:+ now = int(time.time())+ pitr_desc["EarliestRestorableDateTime"] = now+ pitr_desc["LatestRestorableDateTime"] = nowreturn json_response({"ContinuousBackupsDescription": {"ContinuousBackupsStatus": "ENABLED",- "PointInTimeRecoveryDescription": {- "PointInTimeRecoveryStatus": "ENABLED" if pitr_enabled else "DISABLED",- "EarliestRestorableDateTime": 0,- "LatestRestorableDateTime": 0,- }+ "PointInTimeRecoveryDescription": pitr_desc,}})@@ -1376,8 +1405,14 @@ def _update_continuous_backups(data):# ---------------------------------------------------------------------------def _describe_endpoints(data):+ # AWS endpoint discovery: clients call this once and use the returned+ # Address for follow-up calls. Returning real-AWS hostname would redirect+ # SDKs AWAY from MiniStack on cache miss. Return MiniStack's own host so+ # endpoint-discovery-aware SDKs keep talking to us.+ host = os.environ.get("MINISTACK_HOST", "localhost")+ port = os.environ.get("GATEWAY_PORT", "4566")return json_response({- "Endpoints": [{"Address": "dynamodb.us-east-1.amazonaws.com", "CachePeriodInMinutes": 1440}]+ "Endpoints": [{"Address": f"{host}:{port}", "CachePeriodInMinutes": 1440}]})@@ -1457,36 +1492,46 @@ def _enable_kinesis_streaming_destination(data):400,)- dests = _kinesis_destinations.get(table_name, [])- for d in dests:- if d.get("StreamArn") == stream_arn and d.get("DestinationStatus") == "ACTIVE":- return error_response_json(- "ResourceInUseException",- f"Table {table_name} already has an active Kinesis streaming destination for {stream_arn}",- 400,- )-- entry = {- "StreamArn": stream_arn,- "DestinationStatus": "ACTIVE",- "DestinationStatusDescription": "",- "ApproximateCreationDateTimePrecision": precision,- }- # Replace any DISABLED entry for the same ARN; otherwise append.- replaced = False- for i, d in enumerate(dests):- if d.get("StreamArn") == stream_arn:- dests[i] = entry- replaced = True- break- if not replaced:- dests.append(entry)- _kinesis_destinations[table_name] = dests-+ # Lock the check-then-act so two concurrent Enables for the same+ # (table, ARN) cannot both pass the ACTIVE-already check and then both+ # append, leaving duplicate entries in the destinations list. Same lock+ # the TTL reaper and reset() use for module state mutation.+ with _lock:+ dests = _kinesis_destinations.get(table_name, [])+ for d in dests:+ if d.get("StreamArn") == stream_arn and d.get("DestinationStatus") == "ACTIVE":+ return error_response_json(+ "ResourceInUseException",+ f"Table {table_name} already has an active Kinesis streaming destination for {stream_arn}",+ 400,+ )++ entry = {+ "StreamArn": stream_arn,+ "DestinationStatus": "ACTIVE",+ "DestinationStatusDescription": "",+ "ApproximateCreationDateTimePrecision": precision,+ }+ # Replace any DISABLED entry for the same ARN; otherwise append.+ replaced = False+ for i, d in enumerate(dests):+ if d.get("StreamArn") == stream_arn:+ dests[i] = entry+ replaced = True+ break+ if not replaced:+ dests.append(entry)+ _kinesis_destinations[table_name] = dests++ # AWS returns "ENABLING" from Enable; the destination flips to "ACTIVE"+ # eventually. We store ACTIVE so subsequent Describe calls show steady-+ # state, but the immediate response must report the transitional state+ # to match what real AWS returns to a Terraform / SDK consumer that+ # polls on the response field.return json_response({"TableName": table_name,"StreamArn": stream_arn,- "DestinationStatus": "ACTIVE",+ "DestinationStatus": "ENABLING","EnableKinesisStreamingConfiguration": {"ApproximateCreationDateTimePrecision": precision,},@@ -1498,28 +1543,30 @@ def _disable_kinesis_streaming_destination(data):if err:return err- dests = _kinesis_destinations.get(table_name, [])- target = next(- (d for d in dests if d.get("StreamArn") == stream_arn and d.get("DestinationStatus") == "ACTIVE"),- None,- )- if not target:- return error_response_json(- "ResourceNotFoundException",- f"No active Kinesis streaming destination for {stream_arn} on {table_name}",- 400,+ with _lock:+ dests = _kinesis_destinations.get(table_name, [])+ target = next(+ (d for d in dests if d.get("StreamArn") == stream_arn and d.get("DestinationStatus") == "ACTIVE"),+ None,)- target["DestinationStatus"] = "DISABLED"- _kinesis_destinations[table_name] = dests+ if not target:+ return error_response_json(+ "ResourceNotFoundException",+ f"No active Kinesis streaming destination for {stream_arn} on {table_name}",+ 400,+ )+ target["DestinationStatus"] = "DISABLED"+ _kinesis_destinations[table_name] = dests+ precision = target.get("ApproximateCreationDateTimePrecision", "MILLISECOND")+ # AWS returns "DISABLING" from Disable; storage is DISABLED so subsequent+ # Describe shows the steady-state.return json_response({"TableName": table_name,"StreamArn": stream_arn,- "DestinationStatus": "DISABLED",+ "DestinationStatus": "DISABLING","EnableKinesisStreamingConfiguration": {- "ApproximateCreationDateTimePrecision": target.get(- "ApproximateCreationDateTimePrecision", "MILLISECOND"- ),+ "ApproximateCreationDateTimePrecision": precision,},})@@ -1562,27 +1609,31 @@ def _update_kinesis_streaming_destination(data):400,)- dests = _kinesis_destinations.get(table_name, [])- target = next(- (d for d in dests if d.get("StreamArn") == stream_arn and d.get("DestinationStatus") == "ACTIVE"),- None,- )- if not target:- return error_response_json(- "ResourceNotFoundException",- f"No active Kinesis streaming destination for {stream_arn} on {table_name}",- 400,+ with _lock:+ dests = _kinesis_destinations.get(table_name, [])+ target = next(+ (d for d in dests if d.get("StreamArn") == stream_arn and d.get("DestinationStatus") == "ACTIVE"),+ None,)- if precision:- target["ApproximateCreationDateTimePrecision"] = precision- _kinesis_destinations[table_name] = dests+ if not target:+ return error_response_json(+ "ResourceNotFoundException",+ f"No active Kinesis streaming destination for {stream_arn} on {table_name}",+ 400,+ )+ if precision:+ target["ApproximateCreationDateTimePrecision"] = precision+ _kinesis_destinations[table_name] = dests+ applied_precision = target["ApproximateCreationDateTimePrecision"]+ # AWS returns "UPDATING" from Update; storage stays ACTIVE so subsequent+ # Describe shows the steady-state.return json_response({"TableName": table_name,"StreamArn": stream_arn,- "DestinationStatus": "ACTIVE",+ "DestinationStatus": "UPDATING","UpdateKinesisStreamingConfiguration": {- "ApproximateCreationDateTimePrecision": target["ApproximateCreationDateTimePrecision"],+ "ApproximateCreationDateTimePrecision": applied_precision,},})diff --git a/ministack/services/dynamodb_streams.py b/ministack/services/dynamodb_streams.pyindex 58af154c..3c3be17f 100644--- a/ministack/services/dynamodb_streams.py+++ b/ministack/services/dynamodb_streams.py@@ -188,6 +188,18 @@ def _describe_stream(data):table = _ddb._tables.get(table_name, {})key_schema = table.get("KeySchema", [])+ # AWS shard pagination: Limit caps the number of Shards returned (max 100),+ # ExclusiveStartShardId skips past a previously-returned shard. We expose+ # one synthetic shard so this is degenerate, but the fields must be honored+ # for SDK consumers that pass them.+ all_shards = [shard]+ start_shard = data.get("ExclusiveStartShardId")+ if start_shard:+ idx = next((i for i, s in enumerate(all_shards) if s["ShardId"] == start_shard), -1)+ all_shards = all_shards[idx + 1:] if idx >= 0 else []+ limit = min(int(data.get("Limit", 100) or 100), 100)+ page = all_shards[:limit]+description = {"StreamArn": stream_arn,"StreamLabel": info["StreamLabel"],@@ -196,8 +208,10 @@ def _describe_stream(data):"CreationRequestDateTime": table.get("CreationDateTime", 0),"TableName": table_name,"KeySchema": key_schema,- "Shards": [shard],+ "Shards": page,}+ if len(page) == limit and len(all_shards) > limit:+ description["LastEvaluatedShardId"] = page[-1]["ShardId"]return json_response({"StreamDescription": description})diff --git a/ministack/services/kinesis.py b/ministack/services/kinesis.pyindex 7d900607..dddbb641 100644--- a/ministack/services/kinesis.py+++ b/ministack/services/kinesis.py@@ -362,6 +362,32 @@ def _list_streams(data):return json_response({"StreamNames": page, "StreamSummaries": summaries, "HasMoreStreams": has_more})+_LIST_SHARDS_TOKEN_TTL = 300 # AWS contract: tokens expire after 300 seconds.+++def _encode_list_shards_token(after_shard_id: str) -> str:+ """Encode an opaque pagination token for ListShards. AWS uses an opaque+ string; consumers must round-trip it without inspection. We base64url-+ encode a small JSON payload so we can also enforce the AWS 300s TTL."""+ payload = json.dumps({"a": after_shard_id, "t": int(time.time())}, separators=(",", ":"))+ return base64.urlsafe_b64encode(payload.encode("utf-8")).decode("ascii")+++def _decode_list_shards_token(token: str) -> tuple[str | None, str | None]:+ """Return (after_shard_id, error_code). error_code is "ExpiredNextTokenException"+ if the token is past TTL, "InvalidArgumentException" if malformed, else None."""+ try:+ raw = base64.urlsafe_b64decode(token.encode("ascii"))+ obj = json.loads(raw)+ if not isinstance(obj, dict) or "a" not in obj or "t" not in obj:+ return None, "InvalidArgumentException"+ if int(time.time()) - int(obj["t"]) > _LIST_SHARDS_TOKEN_TTL:+ return None, "ExpiredNextTokenException"+ return str(obj["a"]), None+ except (ValueError, json.JSONDecodeError, UnicodeDecodeError):+ return None, "InvalidArgumentException"++def _list_shards(data):name, stream = _resolve_stream(data)if not stream:@@ -376,12 +402,23 @@ def _list_shards(data):if exclusive_start:shard_ids = [s for s in shard_ids if s > exclusive_start]if next_token:- shard_ids = [s for s in shard_ids if s > next_token]+ after, err = _decode_list_shards_token(next_token)+ if err == "ExpiredNextTokenException":+ return error_response_json(+ "ExpiredNextTokenException",+ "NextToken has expired. Tokens expire after 300 seconds.",+ 400,+ )+ if err or after is None:+ return error_response_json(+ "InvalidArgumentException", "Invalid NextToken", 400+ )+ shard_ids = [s for s in shard_ids if s > after]page = shard_ids[:max_results]result = {"Shards": [_shard_out(sid, stream["shards"][sid]) for sid in page]}if len(shard_ids) > max_results:- result["NextToken"] = page[-1]+ result["NextToken"] = _encode_list_shards_token(page[-1])return json_response(result)diff --git a/pyproject.toml b/pyproject.tomlindex 1374a9f5..0f2567d5 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"[project]name = "ministack"-version = "1.3.19"+version = "1.3.20"description = "Free, open-source local AWS emulator — drop-in LocalStack replacement"readme = "README.md"license = { file = "LICENSE" }diff --git a/tests/test_apigatewayv1.py b/tests/test_apigatewayv1.pyindex dffb9f97..3e4a883f 100644--- a/tests/test_apigatewayv1.py+++ b/tests/test_apigatewayv1.py@@ -682,7 +682,8 @@ def test_apigwv1_execute_missing_resource_404(apigw_v1):def test_apigwv1_http_proxy_does_not_block_parallel_ddb(monkeypatch):import asyncio- from ministack.core import nonblocking_http++ from ministack.services import apigateway as apigw_modfrom ministack.services import apigateway_v1 as apigw_v1_modfrom ministack.services import dynamodb as ddb_mod@@ -690,7 +691,9 @@ def test_apigwv1_http_proxy_does_not_block_parallel_ddb(monkeypatch):time.sleep(0.4)return 200, {"Content-Type": "application/json"}, b"{}"- monkeypatch.setattr(nonblocking_http, "_urlopen_sync", _slow_urlopen)+ # _urlopen_async lives on apigateway and is reused by v1; patch the sync+ # helper there so both v1 and v2 tests target the same offload point.+ monkeypatch.setattr(apigw_mod, "_urlopen_sync", _slow_urlopen)async def _run():slow_call = asyncio.create_task(@@ -722,16 +725,17 @@ def test_apigwv1_http_proxy_does_not_block_parallel_ddb(monkeypatch):def test_apigwv1_http_proxy_timeout_is_configurable(monkeypatch):- import importlib- from ministack.services import apigateway_v1 as apigateway_v1_module+ """`_timeout_from_env` honours the env var and falls back on bad input.+ Tested directly instead of via importlib.reload so the suite-wide+ apigateway_v1 module state is not rebuilt mid-run."""+ from ministack.services.apigateway import _timeout_from_envmonkeypatch.setenv("MINISTACK_APIGW_PROXY_TIMEOUT_SECONDS", "55")- reloaded = importlib.reload(apigateway_v1_module)- try:- assert reloaded._PROXY_TIMEOUT_SECONDS == 55.0- finally:- monkeypatch.delenv("MINISTACK_APIGW_PROXY_TIMEOUT_SECONDS", raising=False)- importlib.reload(reloaded)+ assert _timeout_from_env("MINISTACK_APIGW_PROXY_TIMEOUT_SECONDS", 30.0) == 55.0+ monkeypatch.setenv("MINISTACK_APIGW_PROXY_TIMEOUT_SECONDS", "not-a-number")+ assert _timeout_from_env("MINISTACK_APIGW_PROXY_TIMEOUT_SECONDS", 30.0) == 30.0+ monkeypatch.setenv("MINISTACK_APIGW_PROXY_TIMEOUT_SECONDS", "0")+ assert _timeout_from_env("MINISTACK_APIGW_PROXY_TIMEOUT_SECONDS", 30.0) == 30.0def test_apigwv1_no_conflict_with_v2(apigw_v1, apigw, lam):diff --git a/tests/test_apigatewayv2.py b/tests/test_apigatewayv2.pyindex fec8e9e1..ac13b8b3 100644--- a/tests/test_apigatewayv2.py+++ b/tests/test_apigatewayv2.py@@ -4,16 +4,11 @@ import base64import ioimport jsonimport os-import pytestimport threadingimport timeimport uuid as _uuid_modimport zipfilefrom http.server import BaseHTTPRequestHandler, ThreadingHTTPServer-from botocore.exceptions import ClientError-import time-import uuid as _uuid_mod-import zipfilefrom urllib.parse import urlparseimport pytest@@ -846,6 +841,7 @@ def test_apigw_integration_without_request_parameters_optional_map(apigw):def test_apigw_jwt_authorizer_enforced_in_data_plane(apigw):import urllib.error as _urlerrimport urllib.request as _urlreq+from ministack.services import cognito as _cognitoapi_id = apigw.create_api(Name=f"jwt-enforce-{_uuid_mod.uuid4().hex[:8]}", ProtocolType="HTTP")["ApiId"]@@ -959,7 +955,7 @@ def test_apigw_request_mapping_claims_to_headers(apigw):def test_apigw_http_proxy_does_not_block_parallel_ddb(monkeypatch):import asyncio- from ministack.core import nonblocking_http+from ministack.services import apigateway as apigw_modfrom ministack.services import dynamodb as ddb_mod@@ -967,7 +963,7 @@ def test_apigw_http_proxy_does_not_block_parallel_ddb(monkeypatch):time.sleep(0.4)return 200, {"Content-Type": "application/json"}, b"{}"- monkeypatch.setattr(nonblocking_http, "_urlopen_sync", _slow_urlopen)+ monkeypatch.setattr(apigw_mod, "_urlopen_sync", _slow_urlopen)async def _run():slow_call = asyncio.create_task(@@ -999,19 +995,14 @@ def test_apigw_http_proxy_does_not_block_parallel_ddb(monkeypatch):def test_apigw_http_proxy_timeout_is_configurable(monkeypatch):- import importlib- from ministack.services import apigateway as apigateway_module+ """`_timeout_from_env` honours both apigateway timeout env vars.+ Tested directly to avoid importlib.reload churn on session-scoped module state."""+ from ministack.services.apigateway import _timeout_from_envmonkeypatch.setenv("MINISTACK_APIGW_PROXY_TIMEOUT_SECONDS", "41")monkeypatch.setenv("MINISTACK_APIGW_JWKS_TIMEOUT_SECONDS", "9")- reloaded = importlib.reload(apigateway_module)- try:- assert reloaded._PROXY_TIMEOUT_SECONDS == 41.0- assert reloaded._JWKS_TIMEOUT_SECONDS == 9.0- finally:- monkeypatch.delenv("MINISTACK_APIGW_PROXY_TIMEOUT_SECONDS", raising=False)- monkeypatch.delenv("MINISTACK_APIGW_JWKS_TIMEOUT_SECONDS", raising=False)- importlib.reload(reloaded)+ assert _timeout_from_env("MINISTACK_APIGW_PROXY_TIMEOUT_SECONDS", 30.0) == 41.0+ assert _timeout_from_env("MINISTACK_APIGW_JWKS_TIMEOUT_SECONDS", 5.0) == 9.0def test_apigw_routekey_in_lambda_event(apigw, lam):diff --git a/tests/test_dynamodb_kinesis_destination.py b/tests/test_dynamodb_kinesis_destination.pyindex 2b3ebcb9..cb4a6c17 100644--- a/tests/test_dynamodb_kinesis_destination.py+++ b/tests/test_dynamodb_kinesis_destination.py@@ -72,7 +72,9 @@ def test_enable_returns_active_and_describe_lists_it(ddb, kin):resp = ddb.enable_kinesis_streaming_destination(TableName="KdsLifecycle", StreamArn=arn,)- assert resp["DestinationStatus"] == "ACTIVE"+ # AWS returns ENABLING immediately; the destination flips to ACTIVE+ # by the time Describe is called.+ assert resp["DestinationStatus"] == "ENABLING"assert resp["StreamArn"] == arnassert resp["TableName"] == "KdsLifecycle"@@ -145,7 +147,9 @@ def test_disable_stops_delivery(ddb, kin):ddb.put_item(TableName="KdsDisable", Item={"pk": {"S": "before"}})resp = ddb.disable_kinesis_streaming_destination(TableName="KdsDisable", StreamArn=arn)- assert resp["DestinationStatus"] == "DISABLED"+ # AWS returns DISABLING immediately; storage is DISABLED so Describe+ # below shows the steady-state.+ assert resp["DestinationStatus"] == "DISABLING"# Describe still lists the now-DISABLED entry (matches AWS ~24h retention).dests = ddb.describe_kinesis_streaming_destination(TableName="KdsDisable")[@@ -184,7 +188,8 @@ def test_update_precision(ddb, kin):"ApproximateCreationDateTimePrecision": "MICROSECOND",},)- assert resp["DestinationStatus"] == "ACTIVE"+ # AWS returns UPDATING immediately; Describe below shows steady-state ACTIVE.+ assert resp["DestinationStatus"] == "UPDATING"assert (resp["UpdateKinesisStreamingConfiguration"]["ApproximateCreationDateTimePrecision"]== "MICROSECOND"@@ -197,24 +202,37 @@ def test_update_precision(ddb, kin):def test_update_rejects_invalid_precision(ddb, kin):+ """boto3 catches `NANOSECOND` client-side via enum validation, so we hit+ the server with a raw HTTP POST to verify the server-side ValidationException+ actually fires (not just the SDK)."""+ import urllib.error+ import urllib.request+_make_table(ddb, "KdsUpdateInvalid")arn = _make_stream(kin, "ministack-kds-update-invalid")ddb.enable_kinesis_streaming_destination(TableName="KdsUpdateInvalid", StreamArn=arn)- with pytest.raises(ClientError) as ei:- ddb.update_kinesis_streaming_destination(- TableName="KdsUpdateInvalid",- StreamArn=arn,- UpdateKinesisStreamingConfiguration={- "ApproximateCreationDateTimePrecision": "NANOSECOND",- },- )- # boto3 performs client-side enum validation and raises ParamValidationError- # BEFORE the request is sent; fall back to a server-side check with a raw- # call if that's what happened.- err = ei.value- code = getattr(err, "response", {}).get("Error", {}).get("Code", "")- assert code in ("ValidationException", "")+ body = json.dumps({+ "TableName": "KdsUpdateInvalid",+ "StreamArn": arn,+ "UpdateKinesisStreamingConfiguration": {"ApproximateCreationDateTimePrecision": "NANOSECOND"},+ }).encode("utf-8")+ req = urllib.request.Request(+ "http://localhost:4566/",+ data=body,+ headers={+ "Content-Type": "application/x-amz-json-1.0",+ "X-Amz-Target": "DynamoDB_20120810.UpdateKinesisStreamingDestination",+ },+ method="POST",+ )+ try:+ urllib.request.urlopen(req)+ pytest.fail("Expected server to reject NANOSECOND precision")+ except urllib.error.HTTPError as e:+ assert e.code == 400+ err_body = json.loads(e.read().decode("utf-8"))+ assert err_body.get("__type", "").endswith("ValidationException")# ---------------------------------------------------------------------------