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
prerelease (#1900)
Nahuel Nucera94053dd43eba
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d7f25a4f..72668469 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,44 +7,39 @@ Versioning follows [Semantic Versioning](https://semver.org/).## [Unreleased]-### Fixed-- **Lambda — Docker-executor functions reach a `USE_SSL=1` gateway** — the gateway listener serves only HTTPS, but a container's default `AWS_ENDPOINT_URL` was `http://host.docker.internal:<port>`, and its Node shim downgraded a function's `https.request` to the gateway to plain HTTP, which the listener resets. The default endpoint now follows the gateway's scheme and those requests keep TLS. With a gateway certificate that names `host.docker.internal` (`MINISTACK_SSL_CERT`/`MINISTACK_SSL_KEY`), whose CA MiniStack already mounts into these containers, SDK calls from a function succeed. Without `USE_SSL` nothing changes.--- **RDS — `MINISTACK_RDS_PUBLIC_ENDPOINT=1` works with a Compose `hostname:`** — the #1884 fix told a containerised MiniStack from a host-run one by its `HOSTNAME` self-lookup, which a Compose `hostname:` defeats, so instances again stayed `creating`. MiniStack now checks Docker's or Podman's marker file for that, and a containerised MiniStack detects its network as with the setting off (`DOCKER_NETWORK`, then the self-lookup).### Added-- **ElastiCache — serverless caches** — `CreateServerlessCache`, `DescribeServerlessCaches` (with `MaxResults` / `NextToken`), `ModifyServerlessCache` and `DeleteServerlessCache` for `valkey` (major 7, 8 or 9) and `redis` (major 7), with `ServerlessCacheNotFoundFault`, `ServerlessCacheAlreadyExistsFault`, `InvalidServerlessCacheStateFault`, `InvalidParameterCombination` ("No modifications were requested") and `UserGroupNotFound`, and `ListTagsForResource` / `AddTagsToResource` / `RemoveTagsFromResource` on the `serverlesscache` ARN. The cache name is lowercased, as AWS stores it. With Docker, each cache gets its own Valkey or Redis container that, like AWS's, has no plaintext listener: the cache is `creating` until the container answers a TLS `PING`, then `available` with `Endpoint` / `ReaderEndpoint` reachable from the host, and its certificate names that address and chains to a CA served at `GET /_ministack/elasticache/ca.pem` (the local stand-in for Amazon's public CA; clients add it to their trust store; it persists across a restart). `ModifyServerlessCache` accepts only the engine changes AWS does — a same-engine major upgrade, redis to valkey, or the one documented valkey 7 to redis 7 rollback — and rejects the rest with `InvalidParameterCombination` before touching state; an accepted change replaces the container on the same host port, without the data AWS would keep. `StorageEncryptionType` reports `sse-kms` or `sse-elasticache` to match whether `KmsKeyId` is set. The container is removed on delete, reset, and respawned on the same port after a restart with persistence. Differences from AWS: with `DOCKER_NETWORK` the endpoint is the container's address, which changes when the container is replaced; the reader endpoint is the primary's port rather than 6380, memcached serverless caches and serverless snapshots (`SnapshotArnsToRestore`, `FinalSnapshotName`) are refused with `InvalidParameterValue`, and without Docker the endpoint is the plaintext Redis sidecar like other ElastiCache resources. Terraform's `aws_elasticache_serverless_cache` (provider 6.66.0) applies, plans with no changes and destroys. Checked against the botocore model, AWS documentation and the provider's source; not validated against a real AWS account.-- **IoT — registry events** — with a type enabled through `UpdateEventConfigurations`, the thing, thing type, thing type association, thing group, thing group hierarchy and thing group membership operations publish the AWS payload to `$aws/events/...`, where MQTT subscribers and topic rules receive it.+- **IoT — registry events** — with a type enabled through `UpdateEventConfigurations`, the thing, thing type, thing type association, thing group, thing group hierarchy and thing group membership operations publish the AWS payload to `$aws/events/...`, where MQTT subscribers and topic rules receive it. Contributed by @iot-rocket.+- **ElastiCache — serverless caches** — `CreateServerlessCache`, `DescribeServerlessCaches`, `ModifyServerlessCache` and `DeleteServerlessCache` for `valkey` (major 7, 8 or 9) and `redis` (major 7), with tags on the `serverlesscache` ARN. The name is stored lowercase. With Docker each cache gets a TLS-only Valkey or Redis container, `creating` until it answers a TLS `PING`; its certificate chains to the CA at `GET /_ministack/elasticache/ca.pem`. `ModifyServerlessCache` accepts a same-engine major upgrade, redis to valkey, and valkey 7 to redis 7, and rejects other engine changes with `InvalidParameterCombination`. Memcached serverless caches and serverless snapshots are refused with `InvalidParameterValue`; without Docker the endpoint is the plaintext Redis sidecar. Contributed by @skialpine.- **CloudFormation — `AWS::Lambda::Version` updates `FunctionScalingConfig` in place** — a stack update re-ran the create, which published a new version for every change; a `FunctionScalingConfig` change now keeps the version, also when the update rolls back. Contributed by @iot-rocket.--### Fixed-- **API Gateway v2 (HTTP API) — the request path keeps a `%25` escape** — the path was the server's full percent-decode, which also turns `%25` into `%`, so `/items/a%252Eb` reached the Lambda's `rawPath` as `/items/a%2Eb`. Observed on a deployed HTTP API in us-east-1, reached through CloudFront: the Lambda's `rawPath` is `/items/a%252Eb`, while other escapes such as `%2E` are decoded (`a%2Eb` arrives as `a.b`). The HTTP API path now keeps `%25` and decodes the rest as before; `rawPath`, `requestContext.http.path`, `pathParameters` and route matching all use it, so they still agree with each other. REST APIs are unchanged.--- **Step Functions — JSONPath Choice rules read execution context** — `Variable` and supported variable-to-variable comparison paths now resolve `$$.` against the context object, including inside `And`, `Or`, and `Not`. A Choice can check the original execution input after earlier states replace the current input.-- **CloudFormation — `AWS::EC2::VPCGatewayAttachment` updates in place** — a changed `InternetGatewayId` or `VpnGatewayId` moves the attachment under the same `IGW|vpc-…` / `VGW|vpc-…` physical id, `VpnGatewayId` is attached at all, and a `VpcId` change leaves the gateway attached to the new VPC, or to the old one when the update rolls back.-- **CloudFormation — `AWS::Lambda::Version` publishes through `PublishVersion`** — the version takes its `Description`, a version of a function unchanged since its latest version fails with the `AlreadyExists` error AWS reports, `FunctionScalingConfig` on a function without a capacity provider is refused, and a function keeps its `CapacityProviderConfig`. Contributed by @iot-rocket.-- **AppConfig — hosted configuration version numbers are never reused** — a version created after a delete, and the replacement CloudFormation makes for a changed `HostedConfigurationVersion`, get the next unused number instead of overwriting the live one, and a `LatestVersionNumber` mismatch reports the AWS message.-- **CloudFormation — a deleted `AWS::AppConfig::Deployment` stays in `ListDeployments`** — the stack delete removed the deployment, so a replaced deployment left the environment's history and the next one reused its number; it now stays until its environment is deleted, which, through the API or with its stack, also removes its deployments and their tags.--- **CloudFormation — `AWS::ECS::Service` stores `NetworkConfiguration` and `LoadBalancers` in the ECS API shape** — `DescribeServices` returns them in camelCase on create and update, and a service from a template registers its tasks in its target groups.-- **SESv2 — `CreateEmailIdentity`/`GetEmailIdentity` return Easy DKIM tokens for a DOMAIN identity** — a domain identity created without `DkimSigningAttributes` answered an empty `Tokens` list with `Status: NOT_STARTED`. AWS provides a set of DKIM tokens for its CNAME records in that case (Easy DKIM), so the Terraform `aws_sesv2_email_identity` resource's `dkim_signing_attributes[0].tokens` indexing failed. A DOMAIN identity now gets three tokens, `SigningAttributesOrigin: AWS_SES` and `Status: PENDING`, unless `DkimSigningAttributes` brings its own key (BYODKIM); EMAIL_ADDRESS identities are unchanged.-- **API Gateway v2 (HTTP API) — a missing identity source is a 401 without caching too** — a REQUEST authorizer's short circuit for a declared identity source missing from the request only fired with `authorizerResultTtlInSeconds` caching on; with caching off the authorizer was invoked. AWS answers `401 {"message":"Unauthorized"}` (compact JSON) without invoking it either way, as observed on a deployed HTTP API with a TTL of 0. `$context.*` identity sources, which MiniStack does not model, do not count as missing without caching.-### Added--- **CloudFormation — `AWS::ElastiCache::SubnetGroup`, `ParameterGroup`, `CacheCluster`, `ReplicationGroup`, `User` and `UserGroup`** — a template declaring an ElastiCache cache failed with `Unrecognized resource types`. The six types now create, update and delete through the ElastiCache API, so a stack's cluster or replication group gets the same container-backed endpoint `CreateCacheCluster` and `CreateReplicationGroup` return, and its `PrimaryEndPoint` / `RedisEndpoint` can be passed to a Lambda function or ECS task. The create-only properties of the published registry schemas replace the resource (refused for a custom-named one, as on AWS); every other property updates in place through the matching `Modify*` call, a replica count change through `IncreaseReplicaCount` / `DecreaseReplicaCount`, and a parameter the template drops goes back to its default. `ConfigurationEndPoint` is only available on a cluster-mode-enabled replication group and `RedisEndpoint` only on a Valkey or Redis OSS cluster, so a `Fn::GetAtt` on the other fails, as the reference says. Cluster and replication group provisioning runs off the event loop, and a stack waits for a cluster whose image is still being pulled to become `available`. Contributed by @fabio-andre-rodrigues.-- **CloudFormation — `AWS::Glue::Database`, `Table`, `Partition`, `Connection`, `Crawler`, `Job` and `Trigger`** — a template declaring a Glue catalog failed with `Unrecognized resource types`. The seven types now create, update and delete through the Glue control plane, so a stack's tables are the ones the Glue API and Athena read. Ref returns the resource name, or for a partition its `CatalogId|DatabaseName|TableName|values-hash` identifier; `Fn::GetAtt` `Name` works on a connection and `IdentifierPartitionInputValues` on a partition. The create-only properties of the published registry schemas replace the resource (a database's `DatabaseName`, a partition's database, table and `Values`, a connection's name, a crawler's, job's or trigger's `Name`, a trigger's `Type` and `WorkflowName`); renaming a table or moving it to another database replaces it too, and a `DatabaseInput` change, its `Name` included, updates the database in place. A named trigger whose `Type` or `WorkflowName` changes is refused, as for other custom-named resources. Tags are accepted as a map or a Tag list. Crawlers and jobs are only recorded: a stack never starts a crawl or a job run. Contributed by @fabio-andre-rodrigues.+- **CloudFormation — `AWS::Glue::Database`, `Table`, `Partition`, `Connection`, `Crawler`, `Job` and `Trigger`** — a template declaring a Glue catalog failed with `Unrecognized resource types`. The seven types now create, update and delete through the Glue control plane, so a stack's tables are the ones the Glue API and Athena read. Ref returns the resource name, or for a partition its `CatalogId|DatabaseName|TableName|values-hash` identifier; `Fn::GetAtt` `Name` works on a connection and `IdentifierPartitionInputValues` on a partition. The properties the CloudFormation reference marks as replacing replace the resource (a database's `DatabaseName`, a table's name or database, a partition's database, table and `Values`, a connection's name, a crawler's, job's or trigger's `Name`, a trigger's `Type` and `WorkflowName`), and the rest update in place. A `DatabaseInput.Name` change fails with `Database <name> not found` and rolls back, as on AWS. A named trigger whose `Type` or `WorkflowName` changes is refused, as for other custom-named resources. Tags are accepted as a map or a Tag list. Crawlers and jobs are only recorded: a stack never starts a crawl or a job run. Contributed by @fabio-andre-rodrigues.+- **CloudFormation — `AWS::ElastiCache::SubnetGroup`, `ParameterGroup`, `CacheCluster`, `ReplicationGroup`, `User` and `UserGroup`** — a template declaring an ElastiCache cache failed with `Unrecognized resource types`. The six types now create, update and delete through the ElastiCache API, so a stack's cluster or replication group gets the same container-backed endpoint `CreateCacheCluster` and `CreateReplicationGroup` return, and its `PrimaryEndPoint` / `RedisEndpoint` can be passed to a Lambda function or ECS task. The properties the CloudFormation reference marks as replacing replace the resource (refused for a custom-named one, as on AWS), including a cache cluster's `NumCacheNodes` when no Availability Zone is given; every other property updates in place through the matching `Modify*` call, a replica count change through `IncreaseReplicaCount` / `DecreaseReplicaCount`, and a parameter the template drops goes back to its default. `ConfigurationEndPoint` is only available on a cluster-mode-enabled replication group and `RedisEndpoint` only on a Valkey or Redis OSS cluster, so a `Fn::GetAtt` on the other fails, as the reference says. Cluster and replication group provisioning runs off the event loop, and a stack waits for a cluster whose image is still being pulled to become `available`. Contributed by @fabio-andre-rodrigues.- **IoT — `DescribeEventConfigurations` and `UpdateEventConfigurations`** — both answered `Unsupported IoT path`; they now store the registry event switches per account and region, every type starting disabled, an update changing only the types it names, and `creationDate` / `lastModifiedDate` set from the first update on, as on AWS. Contributed by @iot-rocket.- **CloudFormation — `AWS::ServiceDiscovery::HttpNamespace`, `PrivateDnsNamespace`, `PublicDnsNamespace`, `Service` and `Instance`** — a template declaring any of them, as the CDK ECS constructs do for Cloud Map, failed validation with `Unrecognized resource types`. They now create, update and delete through the Cloud Map service, so a DNS namespace from a stack gets its Route 53 hosted zone. `Ref` and `Fn::GetAtt` return the values in the CloudFormation reference; Description, the SOA TTL, a service's `DnsConfig`, `HealthCheckConfig` and `ServiceAttributes`, and instance attributes change in place, while the properties the reference marks as replacing (including `HealthCheckCustomConfig`) replace the resource. Two Cloud Map API changes come with this: namespaces store and update `Properties.DnsProperties.SOA.TTL`, and `DeleteNamespace` removes the namespace's hosted zone, as on AWS. Contributed by @fabio-andre-rodrigues.### Fixed-- **API Gateway v2 — a doubled leading slash still selects the route** — an HTTP API request to `//items/abc` matched no route and got the gateway's `404 {"message":"Not Found"}`. On AWS such a request selects the route: observed on a deployed HTTP API in us-east-1 (its default `execute-api` endpoint) with only `ANY /<prefix>/{proxy+}` routes and no `$default` or `ANY /{proxy+}`, where `//<prefix>/<id>` reached the prefix route's Lambda. Route selection and `pathParameters` now ignore the extra leading slashes; `rawPath` is left as received (not verified against AWS).-- **IAM — customer-managed permissions use the explicit account** — policy evaluation now resolves the complete policy ARN in the principal's account, so a different ambient request account cannot hide that policy or supply a foreign account's document. Permissions continue to follow the policy's current default version.-- **ECS — optional task-definition fields stay omitted** — registering an EC2 task definition without task-level `cpu`, `memory`, or `requiresCompatibilities` no longer invents `256`, `512`, or `["EC2"]` in register, describe, and deregister responses. Explicitly supplied values remain in the definition.+- **API Gateway v2 (HTTP API) — the request path keeps a `%25` escape** — `/items/a%252Eb` reached the Lambda's `rawPath` as `/items/a%2Eb`, because the path was fully percent-decoded. The HTTP API path now keeps `%25` and decodes every other escape as before; `rawPath`, `requestContext.http.path`, `pathParameters` and route matching all use it. Contributed by @skialpine.+- **Step Functions — JSONPath `$$.` paths read the context object** — a Choice rule's `Variable` and its variable-to-variable comparison paths (including inside `And`, `Or` and `Not`), and a state's `InputPath`, `OutputPath` and Map `ItemsPath`, resolved `$$.` against the state input, so a Choice on `$$.Execution.Input` silently took its default branch. They now read the context object, as the AWS context object reference lists for those fields. Contributed by @jayjanssen.+- **CloudFormation — `AWS::EC2::VPCGatewayAttachment` updates in place** — a changed `InternetGatewayId` or `VpnGatewayId` moves the attachment under the same `IGW|vpc-…` / `VGW|vpc-…` physical id, `VpnGatewayId` is attached at all, and a `VpcId` change leaves the gateway attached to the new VPC, or to the old one when the update rolls back. `AttachInternetGateway` on a gateway already attached to a VPC answers `Resource.AlreadyAssociated`, and a stack attaching it to a second VPC leaves it on the first, as AWS does. Contributed by @iot-rocket.+- **CloudFormation — `AWS::Lambda::Version` publishes through `PublishVersion`** — the version takes its `Description`, a version of a function unchanged since its latest version fails with the `AlreadyExists` error AWS reports, `FunctionScalingConfig` on a function without a capacity provider is refused, and a function keeps its `CapacityProviderConfig`. Contributed by @iot-rocket.+- **AppConfig — hosted configuration version numbers are never reused** — a version created after a delete, and the replacement CloudFormation makes for a changed `HostedConfigurationVersion`, get the next unused number instead of overwriting the live one, and a `LatestVersionNumber` mismatch reports the AWS message. Contributed by @iot-rocket.+- **CloudFormation — a deleted `AWS::AppConfig::Deployment` stays in `ListDeployments`** — the stack delete removed the deployment, so a replaced deployment left the environment's history and the next one reused its number; it now stays until its environment is deleted, which, through the API or with its stack, also removes its deployments and their tags. Contributed by @iot-rocket.+- **CloudFormation — `AWS::ECS::Service` stores `NetworkConfiguration` and `LoadBalancers` in the ECS API shape** — `DescribeServices` returns them in camelCase on create and update, and a service from a template registers its tasks in its target groups. Contributed by @iot-rocket.+- **SESv2 — `CreateEmailIdentity`/`GetEmailIdentity` return Easy DKIM tokens for a DOMAIN identity** — a domain identity created without `DkimSigningAttributes` answered an empty `Tokens` list with `Status: NOT_STARTED`. AWS provides a set of DKIM tokens for its CNAME records in that case (Easy DKIM), so the Terraform `aws_sesv2_email_identity` resource's `dkim_signing_attributes[0].tokens` indexing failed. A DOMAIN identity now gets three tokens, `SigningAttributesOrigin: AWS_SES` and `Status: PENDING`, unless `DkimSigningAttributes` brings its own key (BYODKIM); EMAIL_ADDRESS identities are unchanged. Contributed by @skialpine.+- **Lambda — functions reach a `USE_SSL=1` gateway** — the gateway listener serves only HTTPS, but a function's default `AWS_ENDPOINT_URL` was plain HTTP in every executor (Docker, the warm worker and the local subprocess), and the Docker executor's Node shim downgraded a function's `https.request` to the gateway to HTTP, which the listener resets. The default endpoint now follows the gateway's scheme, the shim keeps TLS, and a host process trusts the gateway's certificate through `AWS_CA_BUNDLE` / `REQUESTS_CA_BUNDLE` / `NODE_EXTRA_CA_CERTS` unless they are already set. Without `USE_SSL` nothing changes. Contributed by @skialpine.+- **RDS — `MINISTACK_RDS_PUBLIC_ENDPOINT=1` works with a Compose `hostname:`** — a containerised MiniStack whose container sets a hostname left instances `creating`, because the self-lookup by `HOSTNAME` found no container. A containerised MiniStack now detects its network as with the setting off (`DOCKER_NETWORK`, then the self-lookup). Contributed by @skialpine.+- **IoT — `DeleteThingGroup` refuses a group with child groups** — the delete went through and left the children pointing at a missing parent; it now fails with `InvalidRequestException` "Cannot delete thing group : {name} when there are still child groups attached to it", and a CloudFormation stack delete that reaches such a group ends in `DELETE_FAILED`. Contributed by @iot-rocket.+- **IoT — `UpdateThing` honours `removeThingType`** — the flag was ignored, so the thing kept its type, and an update without `attributePayload` cleared the attributes. Contributed by @iot-rocket.+- **API Gateway v2 (HTTP API) — a doubled leading slash still selects the route** — a request to `//items/abc` matched no route and answered `404 {"message":"Not Found"}`. Route selection and `pathParameters` now ignore the extra leading slashes; `rawPath` keeps the path as received. Contributed by @skialpine.+- **Cloud Map — `DeleteNamespace` refuses a namespace that still has services** — it deleted the namespace (and now its hosted zone) anyway. It answers `400 ResourceInUse` "Namespace has associated services; delete the services before deleting the namespace", as on AWS.+- **Lambda — `PublishVersion` of an unchanged function returns the latest version** — it published a new version every time; AWS doesn't publish when the code and configuration haven't changed since the last version, and returns that version with its original description.+- **API Gateway v2 (HTTP API) — REQUEST authorizer identity sources** — a declared identity source missing from the request answers `401 {"message":"Unauthorized"}` without invoking the authorizer, cached or not (it required caching). `$context.*` sources such as `$context.routeKey` are resolved from the request instead of counting as missing, so an authorizer caching per route no longer answered 401 to every request. Contributed by @skialpine.+- **ECS — optional task-definition fields stay omitted** — registering an EC2 task definition without task-level `cpu`, `memory`, or `requiresCompatibilities` no longer invents `256`, `512`, or `["EC2"]` in register, describe, and deregister responses. Explicitly supplied values remain in the definition. Contributed by @AdrianAcala.+- **IAM — customer-managed permissions use the explicit account** — policy evaluation now resolves the complete policy ARN in the principal's account, so a different ambient request account cannot hide that policy or supply a foreign account's document. Permissions continue to follow the policy's current default version. Contributed by @AdrianAcala.- **Cognito — `USER_SRP_AUTH` checks the password** — `PASSWORD_VERIFIER` answered random `SALT` and `SRP_B` values and accepted any response, so a wrong password, a missing `TIMESTAMP` or a disabled or unconfirmed user all got tokens. The challenge now carries SRP-6a parameters with a stable salt per user, and the response is refused with `NotAuthorizedException` unless its signature proves the stored password. `TIMESTAMP` must read `EEE MMM d HH:mm:ss z yyyy` with `UTC` or `GMT` as the zone, the signature is computed over its canonical form, `PASSWORD_CLAIM_SIGNATURE` must be base64, and a temporary password leads to `NEW_PASSWORD_REQUIRED`. A client without `ALLOW_USER_SRP_AUTH`, an unknown user under `LEGACY`, a disabled and an unconfirmed user are refused at `InitiateAuth`. The built-in `PASSWORD_VERIFIER` step of `CUSTOM_WITH_SRP` gets the same check. Contributed by @iot-rocket.- **Cognito — refresh tokens are checked against the pool and client** — `REFRESH_TOKEN_AUTH` (`InitiateAuth`, `AdminInitiateAuth`) and `GetTokensFromRefreshToken` issued tokens for the first user in the pool when the refresh token was malformed, from another pool or of a deleted user, and accepted a token issued to another client; they now answer `NotAuthorizedException` with the message AWS gives for each case, and the refresh token from a SAML or OIDC federated sign-in now refreshes the federated user's session. Contributed by @iot-rocket.- **CloudFormation — `AWS::S3Tables::TableBucket` and `AWS::S3Tables::Table` update in place** — a stack update re-ran the create, which reset the bucket's `createdAt` and rebuilt the table with a new `createdAt` and its initial metadata location, dropping committed metadata; a maintenance setting or tag change now keeps both, and a create-only table change under an unchanged name fails with the conflict AWS reports. Contributed by @iot-rocket.-- **RDS — `DescribeGlobalClusters` lists clusters as `GlobalClusterMember`** — each cluster was a `<GlobalCluster>` element, so SDKs that match the list member name, such as aws-sdk-go-v2, found none. Contributed by @IamYipi.- **Amazon MQ — `DescribeBrokerInstanceOptions` returns `supportedEngineVersions` as strings** — they were `{"name": ...}` objects, which aws-sdk-go-v2 could not deserialize. Contributed by @IamYipi.- **EventBridge — `UpdateEventBus` returns the bus** — it answered `EventBusArn` and `LastModifiedTime`, which are not response members, so SDKs returned nothing; it now returns `Arn`, `Name` and the bus's `Description`, `KmsKeyIdentifier`, `DeadLetterConfig` and `LogConfig`. Contributed by @IamYipi.@@ -54,9 +49,8 @@ Versioning follows [Semantic Versioning](https://semver.org/).- **SQS — `QueueUrl` matches the gateway's TLS scheme (`USE_SSL=1`)** — `CreateQueue`/`GetQueueUrl`/`ListQueues` always returned `http://` URLs, and the AWS SDK v3 uses the QueueUrl itself as the request endpoint (`useQueueUrlAsEndpoint` defaults true), so a client handed that URL left the TLS-only gateway. The `AWS::SQS::Queue` CloudFormation provisioner built the same hardcoded scheme and now reuses the shared helper. Contributed by @skialpine.- **API Gateway v2 (HTTP API) — a request no stage or route matches answers AWS's exact 404 body** — an unmatched route answered `{"message": "No route found"}` and an unknown stage `{"message": "Stage '…' not found"}`; both now answer `{"message":"Not Found"}` (compact JSON), as AWS does. Contributed by @skialpine.- **API Gateway v2 — `apiEndpoint` follows the gateway's TLS scheme** — with `USE_SSL=1` the gateway listener serves only HTTPS, but CreateApi and the `AWS::ApiGatewayV2::Api` CloudFormation resource always returned an `http://` `apiEndpoint`, which nothing answers. They now return `https://`, or `wss://` for a WebSocket API, as AWS does. Without `USE_SSL` the endpoint keeps `http://`. Contributed by @skialpine.-- **IAM — condition value lists and request-tag key matching** — negated conditions now match only when none of their policy values match, so a `StringNotEquals` deny listing permitted values no longer denies one of those values. Request-tag condition keys match every tag name without regard to case, including names that differ only by case; affirmative conditions match any of those values and negated conditions match none. Comparisons of tag values keep the selected operator's case rules.--- **SSM — parameter tag actions authorize the parameter named by `ResourceId`** — with `AUTH=true`, `AddTagsToResource`, `RemoveTagsFromResource`, and `ListTagsForResource` checked `Name` instead, so an exact ARN allow could fail and an exact ARN deny could be missed under a broad allow. Accepted parameter-name and ARN aliases now use the canonical parameter ARN for the IAM check. Tag authorization denials now match AWS's HTTP 400 JSON 1.1 response, including the canonical resource and explicit-deny reason.+- **IAM — condition value lists and request-tag key matching** — negated conditions now match only when none of their policy values match, so a `StringNotEquals` deny listing permitted values no longer denies one of those values. Request-tag condition keys match every tag name without regard to case, including names that differ only by case; affirmative conditions match any of those values and negated conditions match none. Comparisons of tag values keep the selected operator's case rules. Contributed by @AdrianAcala.+- **SSM — parameter tag actions authorize the parameter named by `ResourceId`** — with `AUTH=true`, `AddTagsToResource`, `RemoveTagsFromResource`, and `ListTagsForResource` checked `Name` instead, so an exact ARN allow could fail and an exact ARN deny could be missed under a broad allow. Accepted parameter-name and ARN aliases now use the canonical parameter ARN for the IAM check. SSM authorization denials now match AWS's HTTP 400 JSON 1.1 response, including the canonical resource and explicit-deny reason. Contributed by @AdrianAcala.## [1.5.19] — 2026-09-30diff --git a/ministack/core/iam_actions.py b/ministack/core/iam_actions.pyindex c7ad73ae..b1c179b7 100644--- a/ministack/core/iam_actions.py+++ b/ministack/core/iam_actions.py@@ -1749,11 +1749,9 @@ def access_denied_response(service: str, action: str, principal_arn: str,catching AccessDenied misses it. `headers` lets the services that acceptmore than one encoding answer in the one the request arrived in."""- if service == "ssm" and not error_code and action in {- "ssm:AddTagsToResource", "ssm:RemoveTagsFromResource", "ssm:ListTagsForResource",- }:- # Live AWS us-west-2: SSM tag authorization denials are HTTP 400,- # JSON 1.1, with a capitalized Message and the authorized resource.+ if service == "ssm" and not error_code:+ # SSM authorization denials are HTTP 400, JSON 1.1, with a capitalized+ # Message naming the resource.reason = ("with an explicit deny in an identity-based policy" if explicit_denyelse f"because no identity-based policy allows the {action} action"diff --git a/ministack/core/lambda_runtime.py b/ministack/core/lambda_runtime.pyindex 57a36345..733bfaea 100644--- a/ministack/core/lambda_runtime.py+++ b/ministack/core/lambda_runtime.py@@ -1183,7 +1183,13 @@ class Worker:# already present; setdefault only fills in the default when neither# the function nor the host set one.port = os.environ.get("GATEWAY_PORT", os.environ.get("EDGE_PORT", "4566"))- spawn_env.setdefault("AWS_ENDPOINT_URL", f"http://127.0.0.1:{port}")+ from ministack.core import tls as _tls+ if "AWS_ENDPOINT_URL" not in spawn_env:+ if _tls.use_ssl_enabled():+ spawn_env["AWS_ENDPOINT_URL"] = f"https://127.0.0.1:{port}"+ _tls.trust_gateway_cert(spawn_env)+ else:+ spawn_env["AWS_ENDPOINT_URL"] = f"http://127.0.0.1:{port}"if "LOCALSTACK_HOSTNAME" in os.environ:spawn_env["LOCALSTACK_HOSTNAME"] = os.environ["LOCALSTACK_HOSTNAME"]spawn_env.setdefault("LAMBDA_TASK_ROOT", code_dir)diff --git a/ministack/core/tls.py b/ministack/core/tls.pyindex f193477c..6a8a43e2 100644--- a/ministack/core/tls.py+++ b/ministack/core/tls.py@@ -107,6 +107,21 @@ def _cert_names(cert_path: str, names: "list[str]") -> bool:return all(f"DNS:{name}" in (out.stdout or "") for name in names)+def trust_gateway_cert(env: dict) -> None:+ """Have a host process trust the gateway's certificate, unless env already names a CA."""+ try:+ cert_path, _key_path = resolve_tls_material()+ except SystemExit:+ return+ if not os.path.exists(cert_path):+ return+ env.setdefault("NODE_EXTRA_CA_CERTS", cert_path)+ bundle = ca_bundle_path(cert_path)+ if bundle:+ for var in ("AWS_CA_BUNDLE", "REQUESTS_CA_BUNDLE"):+ env.setdefault(var, bundle)++def resolve_tls_material() -> "tuple[str, str]":"""Return (certfile, keyfile) PEM paths.diff --git a/ministack/services/apigateway.py b/ministack/services/apigateway.pyindex 28459bcb..ea7f2339 100644--- a/ministack/services/apigateway.py+++ b/ministack/services/apigateway.py@@ -874,7 +874,8 @@ def _evaluate_authorizer_policy(policy_doc, route_arn):return "Allow" if allow else "NoMatch"-def _request_authorizer_identity_sources(identity_source, headers, query_params, stage_vars):+def _request_authorizer_identity_sources(identity_source, headers, query_params, stage_vars,+ context=None):"""Resolve a REQUEST authorizer's identitySource list to (all_present, values).HTTP API identitySource entries use `$request.header.*` / `$request.querystring.*`@@ -896,7 +897,8 @@ def _request_authorizer_identity_sources(identity_source, headers, query_params,val = (qv[0] if isinstance(qv, list) else qv) or ""elif src.startswith("$stageVariables."):val = (stage_vars or {}).get(src[len("$stageVariables."):]) or ""- # $context.* identity sources are not modeled; treated as absent.+ elif src.startswith("$context."):+ val = (context or {}).get(src[len("$context."):]) or ""values.append(val)if not val:present = False@@ -987,8 +989,14 @@ async def _authorize_request_v2(ttl = _authorizer_ttl(authorizer)identity_source = authorizer.get("identitySource") or []+ context = {+ "routeKey": route.get("routeKey", "$default"), "stage": stage, "apiId": api_id,+ "accountId": owner_account_id, "httpMethod": method, "path": path,+ "domainName": f"{api_id}.execute-api.{_HOST}",+ "identity.sourceIp": "127.0.0.1", "identity.userAgent": headers.get("user-agent", ""),+ }all_present, id_values = _request_authorizer_identity_sources(- identity_source, headers, query_params, stage_vars+ identity_source, headers, query_params, stage_vars, context)# "To enable caching, your authorizer must have at least one identity# source": the identity values ARE the cache key, so with none declared@@ -996,14 +1004,8 @@ async def _authorize_request_v2(# the first caller's result.caching = ttl > 0 and bool(identity_source)# A declared identity source missing from the request is a 401 without- # invoking the Lambda, cached or not, with AWS's compact body (observed on a- # deployed HTTP API). $context.* sources are not modeled, so uncached they- # never count as missing.- modeled_present, _ = _request_authorizer_identity_sources(- [s for s in identity_source if not str(s).startswith("$context.")],- headers, query_params, stage_vars,- )- if identity_source and not (all_present if caching else modeled_present):+ # invoking the Lambda, cached or not.+ if identity_source and not all_present:return (401, {"Content-Type": "application/json"}, b'{"message":"Unauthorized"}'), Noneidentity_values = tuple(id_values)@@ -1287,7 +1289,7 @@ async def handle_execute(api_id, stage, path, method, headers, body, query_param"""Execute an API request through a deployed API (data plane)."""scope = find_api_scope(api_id)if scope is None:- return 404, {"Content-Type": "application/json"}, json.dumps({"message": "Not Found"}).encode()+ return _http_api_not_found()owner_account_id, owner_region = scopefrom ministack.core.responses import _request_account_id, _request_region@@ -1304,13 +1306,18 @@ async def handle_execute(api_id, stage, path, method, headers, body, query_param_request_region.reset(region_token)+def _http_api_not_found():+ """AWS's 404 for a request no stage or route of an HTTP API matches."""+ return 404, {"Content-Type": "application/json"}, b'{"message":"Not Found"}'++async def _handle_execute_in_scope(api_id, stage, path, method, headers, body, query_params,owner_account_id, owner_region,):api = _apis.get(api_id)if not api:- return 404, {"Content-Type": "application/json"}, json.dumps({"message": "Not Found"}).encode()+ return _http_api_not_found()# CORS preflight: served from the API's corsConfiguration before any route# matching, because AWS responds to OPTIONS itself without invoking the@@ -1321,18 +1328,13 @@ async def _handle_execute_in_scope(api_stages = _stages.get(api_id, {})if stage not in api_stages and stage != "$default":- return 404, {"Content-Type": "application/json"}, json.dumps({"message": f"Stage '{stage}' not found"}).encode()+ return _http_api_not_found()# AWS selects the route of a path with extra leading slashes as if it had one.route_path_in = "/" + path.lstrip("/")route = _match_route(api_id, method, route_path_in)if not route:- # AWS's body for an unmatched HTTP API route: compact JSON.- return (- 404,- {"Content-Type": "application/json"},- json.dumps({"message": "Not Found"}, separators=(",", ":")).encode(),- )+ return _http_api_not_found()request_headers = {k.lower(): v for k, v in (headers or {}).items()}route_key = route.get("routeKey", "$default")diff --git a/ministack/services/cloudformation/provisioners.py b/ministack/services/cloudformation/provisioners.pyindex 09c896a5..7c639af8 100644--- a/ministack/services/cloudformation/provisioners.py+++ b/ministack/services/cloudformation/provisioners.py@@ -720,17 +720,11 @@ _CUSTOM_NAME_REPLACEMENT = {old.get("Scope", "REGIONAL") != new.get("Scope", "REGIONAL")),},- # createOnlyProperties of the published registry schemas, the name itself- # aside. "If you specify a name, you can't perform updates that require- # replacement" (aws-properties-name).+ # "Update requires: Replacement" in the template reference, the name+ # itself aside."AWS::ElastiCache::CacheCluster": {"name": "ClusterName",- "requires_replacement": lambda old, new: any(- old.get(p) != new.get(p) for p in (- "Port", "SnapshotArns", "SnapshotName", "CacheSubnetGroupName",- "Engine", "NetworkType",- )- ),+ "requires_replacement": lambda old, new: _ec_cluster_requires_replacement(old, new),},"AWS::ElastiCache::ReplicationGroup": {"name": "ReplicationGroupId",@@ -6676,6 +6670,18 @@ def _ecr_repo_delete(physical_id, props):# --- CodeBuild Project provisioner ---+def _codebuild_cfn_to_api(value):+ """Spell a Source, Artifacts or Environment property the way the CodeBuild+ API does. The template PascalCases the API's camelCase members (Type,+ Image, EnvironmentVariables, ...) and calls the inline build spec BuildSpec+ where the API has ``buildspec``; the build runner reads the API names.+ """+ value = _pascal_to_camel(value)+ if isinstance(value, dict) and "buildSpec" in value:+ value["buildspec"] = value.pop("buildSpec")+ return value++def _codebuild_project_create(logical_id, props, stack_name):name = props.get("Name") or _physical_name(stack_name, logical_id, max_len=255)@@ -6686,14 +6692,14 @@ def _codebuild_project_create(logical_id, props, stack_name):data = {"name": name,"description": props.get("Description", ""),- "source": props.get("Source", {"type": "NO_SOURCE"}),+ "source": _codebuild_cfn_to_api(props.get("Source", {"type": "NO_SOURCE"})),"sourceVersion": props.get("SourceVersion", ""),- "artifacts": props.get("Artifacts", {"type": "NO_ARTIFACTS"}),- "environment": props.get("Environment", {+ "artifacts": _codebuild_cfn_to_api(props.get("Artifacts", {"type": "NO_ARTIFACTS"})),+ "environment": _codebuild_cfn_to_api(props.get("Environment", {"type": "LINUX_CONTAINER","image": "aws/codebuild/standard:7.0","computeType": "BUILD_GENERAL1_SMALL",- }),+ })),"serviceRole": props.get("ServiceRole", f"arn:aws:iam::{get_account_id()}:role/codebuild-role"),"timeoutInMinutes": int(props.get("TimeoutInMinutes", 60)),"tags": [{"key": t["Key"], "value": t["Value"]} for t in props.get("Tags", [])],@@ -7385,11 +7391,19 @@ def _ec2_vpc_gw_attachment(props):{"VpcId": vpc_id, "State": "available"}, f"IGW|{vpc_id}")-def _ec2_vpc_gw_attach_create(logical_id, props, stack_name):- """Attach the gateway; a replaced attachment stays until its own delete."""+def _ec2_vpc_gw_attach_create(logical_id, props, stack_name, replacing=False):+ """Attach the gateway; a replaced attachment stays until its own delete.++ An internet gateway attaches to one VPC at a time. CloudFormation ignores+ AttachInternetGateway's Resource.AlreadyAssociated, so a gateway already on+ another VPC stays there; only this resource's own replacement may briefly+ hold both until the old attachment is deleted.+ """gateway, attachment, physical_id = _ec2_vpc_gw_attachment(props)if gateway:_ec2_vpc_gw_attach_delete(physical_id, props)+ if gateway.get("InternetGatewayId") and gateway["Attachments"] and not replacing:+ return physical_id, {}gateway["Attachments"].append(attachment)return physical_id, {}@@ -7399,7 +7413,8 @@ def _ec2_vpc_gw_attach_update(physical_id, old_props, new_props, stack_name, logreplaced = _rename_replacement(physical_id, old_props, new_props, stack_name, logical_id,_ec2_vpc_gw_attachment(new_props)[2], _ec2_vpc_gw_attachment(old_props)[2],- _ec2_vpc_gw_attach_create, _ec2_vpc_gw_attach_delete,+ lambda lid, props, stack: _ec2_vpc_gw_attach_create(lid, props, stack, replacing=True),+ _ec2_vpc_gw_attach_delete,)if replaced is not None:return replaced@@ -7621,11 +7636,8 @@ def _ecs_task_def_create(logical_id, props, stack_name):"revision": revision,"status": "ACTIVE","containerDefinitions": _normalize_container_defs(props.get("ContainerDefinitions", [])),- "requiresCompatibilities": compat,"compatibilities": compat + (["EC2"] if "FARGATE" in compat and "EC2" not in compat else []),"networkMode": props.get("NetworkMode", "bridge"),- "cpu": props.get("Cpu", "256"),- "memory": props.get("Memory", "512"),"executionRoleArn": props.get("ExecutionRoleArn", ""),"taskRoleArn": props.get("TaskRoleArn", ""),"volumes": props.get("Volumes", []),@@ -7635,6 +7647,10 @@ def _ecs_task_def_create(logical_id, props, stack_name):"registeredAt": now_iso(),"registeredBy": f"arn:aws:iam::{get_account_id()}:root",}+ for prop, key in (("RequiresCompatibilities", "requiresCompatibilities"), ("Cpu", "cpu"),+ ("Memory", "memory")):+ if prop in props:+ td[key] = props[prop]_ecs._task_defs[td_key] = td_ecs._task_def_latest[family] = revisionreturn arn, {"TaskDefinitionArn": arn}@@ -10772,15 +10788,15 @@ def _firehose_delivery_stream_delete(physical_id, props):# groups, users and user groups (#1874) ---# Each type goes through elasticache.py's own query-protocol functions, so a# stack's cluster or replication group gets the same container-backed endpoint-# CreateCacheCluster / CreateReplicationGroup return. Create-only properties-# follow the published registry schemas; every other property updates in+# CreateCacheCluster / CreateReplicationGroup return. Replacement follows the+# template reference's "Update requires"; every other property updates in# place through the matching Modify call, which, like the API, ignores the# members MiniStack does not model. Ref is the resource name for every type.# A cluster created while its image is still being pulled reports `creating`# and publishes its endpoint when the container starts; CloudFormation waits# for `available` before the resource completes.-_EC_AVAILABLE_TIMEOUT = float(os.environ.get("MINISTACK_ELASTICACHE_CFN_WAIT", "300"))+_EC_AVAILABLE_TIMEOUT = 300def _ec_query(props, renames=None):@@ -10819,27 +10835,6 @@ def _ec_call(fn, params, resource_type, action):def _ec_sync_tags(arn, old_props, new_props, resource_type):-# --- Glue Data Catalog, connections, crawlers, jobs and triggers (#1875) ----# Each type goes through glue.py's own control-plane functions, so a stack's-# databases and tables are the catalog Athena and the Glue API read. Crawlers-# and jobs are records only: a stack never starts a crawl or a job run. Ref-# is the resource name for every type except the partition, whose Ref is its-# compound primary identifier. Create-only properties follow the published-# registry schemas. Deletes ignore EntityNotFound, since deleting a database-# already drops its tables and partitions.---def _glue_call(fn, data, resource_type, action):- status, _headers, body = fn(data)- if status >= 400:- raise ValueError(f"{resource_type} {action} failed: {body!r}")- return json.loads(body or b"{}")---def _glue_sync_tags(arn, old_props, new_props, resource_type):- """Apply a Tags change through TagResource / UntagResource. The registry- schemas type Tags as a map, while the template reference pages say Tag- list; _tag_map reads both."""old_tags = _tag_map(old_props.get("Tags"))new_tags = _tag_map(new_props.get("Tags"))removed = sorted(old_tags.keys() - new_tags.keys())@@ -10994,6 +10989,16 @@ def _ec_wait_available(records, record_id, status_key, resource_type):return rec+def _ec_cluster_requires_replacement(old, new):+ # NumCacheNodes replaces when no Availability Zone was given before or now.+ no_azs = not any(p.get(k) for p in (old, new)+ for k in ("PreferredAvailabilityZone", "PreferredAvailabilityZones"))+ return (any(old.get(p) != new.get(p) for p in (+ "Port", "SnapshotArns", "SnapshotName", "CacheSubnetGroupName",+ "Engine", "NetworkType"))+ or (no_azs and int(old.get("NumCacheNodes") or 1) != int(new.get("NumCacheNodes") or 1)))++def _ec_cluster_attrs(cluster_id):rec = _ec._clusters.get(cluster_id) or {}ep = rec.get("_endpoint") or {}@@ -11232,6 +11237,33 @@ def _ec_user_group_update(physical_id, old_props, new_props, stack_name, logicaldef _ec_user_group_delete(physical_id, props):_ec._delete_user_group({"UserGroupId": physical_id})+++# --- Glue Data Catalog, connections, crawlers, jobs and triggers (#1875) ---+# Each type goes through glue.py's own control-plane functions, so a stack's+# databases and tables are the catalog Athena and the Glue API read. Crawlers+# and jobs are records only: a stack never starts a crawl or a job run. Ref+# is the resource name for every type except the partition, whose Ref is its+# compound primary identifier. Replacement follows the template reference's+# "Update requires". Deletes ignore EntityNotFound, since deleting a database+# already drops its tables and partitions.+++def _glue_call(fn, data, resource_type, action):+ status, _headers, body = fn(data)+ if status >= 400:+ raise ValueError(f"{resource_type} {action} failed: {body!r}")+ return json.loads(body or b"{}")+++def _glue_sync_tags(arn, old_props, new_props, resource_type):+ """Apply a Tags change through TagResource / UntagResource. The registry+ schemas type Tags as a map, while the template reference pages say Tag+ list; _tag_map reads both."""+ old_tags = _tag_map(old_props.get("Tags"))+ new_tags = _tag_map(new_props.get("Tags"))+ removed = sorted(old_tags.keys() - new_tags.keys())+ if removed:_glue_call(_glue._untag_resource, {"ResourceArn": arn, "TagsToRemove": removed},resource_type, "untag")if new_tags and new_tags != old_tags:@@ -11265,16 +11297,16 @@ def _glue_database_create(logical_id, props, stack_name):def _glue_database_update(physical_id, old_props, new_props, stack_name, logical_id=None):- # The registry schema's only create-only property is DatabaseName, and its- # update handler is granted glue:UpdateDatabase but neither CreateDatabase- # nor DeleteDatabase: a DatabaseInput change, its Name included, updates- # the database in place under the same Ref.declared = new_props.get("DatabaseName")if physical_id not in _glue._databases or (declared and declared != physical_id):created = _glue_database_create(logical_id or physical_id, new_props, stack_name)if physical_id in _glue._databases and created[0] != physical_id:_delete_predecessor(_glue_database_delete, physical_id, old_props)return created+ # AWS updates by the new DatabaseInput.Name, which does not exist yet.+ requested = (new_props.get("DatabaseInput") or {}).get("Name")+ if not declared and requested and requested.lower() != physical_id.lower():+ raise ValueError(f"Database {requested} not found")name = physical_iddb_input = _glue_database_input(name, new_props)db_input.update(_glue_reset_dropped(@@ -12209,7 +12241,10 @@ def _codebuild_project_update(physical_id, old_props, new_props, stack_name):("SourceVersion", "sourceVersion"), ("Artifacts", "artifacts"),("Environment", "environment"), ("ServiceRole", "serviceRole")):if prop in new_props:- project[key] = new_props[prop]+ value = new_props[prop]+ if prop in ("Source", "Artifacts", "Environment"):+ value = _codebuild_cfn_to_api(value)+ project[key] = valueif "TimeoutInMinutes" in new_props:project["timeoutInMinutes"] = int(new_props["TimeoutInMinutes"])_reconcile_tag_list(project.setdefault("tags", []), old_props, new_props,@@ -12393,7 +12428,6 @@ _REPLACING_PROPERTIES: dict[str, tuple[str, ...]] = {"LayerName", "Content", "CompatibleRuntimes", "CompatibleArchitectures","Description", "LicenseInfo",),- # createOnlyProperties of the published registry schemas."AWS::ElastiCache::SubnetGroup": ("CacheSubnetGroupName",),"AWS::ElastiCache::ParameterGroup": ("CacheParameterGroupFamily",),"AWS::ElastiCache::CacheCluster": (@@ -12407,10 +12441,8 @@ _REPLACING_PROPERTIES: dict[str, tuple[str, ...]] = {),"AWS::ElastiCache::User": ("UserId", "UserName"),"AWS::ElastiCache::UserGroup": ("UserGroupId",),- # createOnlyProperties of the published registry schemas. Table,- # Partition and Connection are left out: the first replaces on a- # TableInput.Name change the schema does not list, and the other two have- # nested create-only members (PartitionInput/Values, ConnectionInput/Name).+ # Table, Partition and Connection replace on nested members+ # (TableInput.Name, PartitionInput.Values, ConnectionInput.Name)."AWS::Glue::Database": ("DatabaseName",),"AWS::Glue::Crawler": ("Name",),"AWS::Glue::Job": ("Name",),@@ -12421,9 +12453,8 @@ _REPLACING_PROPERTIES: dict[str, tuple[str, ...]] = {_CONDITIONALLY_REPLACING_PROPERTIES: dict[str, tuple[str, ...]] = {"AWS::DynamoDB::Table": ("KeySchema",),"AWS::Lambda::Function": ("DurableConfig",),- # conditionalCreateOnlyProperties of the published registry schemas.- "AWS::ElastiCache::CacheCluster": ("PreferredAvailabilityZones", "IpDiscovery"),- "AWS::ElastiCache::ReplicationGroup": ("AuthToken", "NodeGroupConfiguration"),+ "AWS::ElastiCache::CacheCluster": ("NumCacheNodes",),+ "AWS::ElastiCache::ReplicationGroup": ("AuthToken", "NodeGroupConfiguration", "NumNodeGroups"),}@@ -12488,6 +12519,7 @@ _RESOURCE_HANDLERS = {"update": _ec_user_group_update,"update_with_logical_id": True,"delete": _ec_user_group_delete,+ },"AWS::Glue::Database": {"create": _glue_database_create,"update": _glue_database_update,diff --git a/ministack/services/ec2.py b/ministack/services/ec2.pyindex 37386e1c..3fbc47f9 100644--- a/ministack/services/ec2.py+++ b/ministack/services/ec2.py@@ -3070,6 +3070,11 @@ def _attach_internet_gateway(p):if not igw:return _error("InvalidInternetGatewayID.NotFound",f"The internet gateway ID '{igw_id}' does not exist", 400)+ if igw.get("Attachments"):+ # An internet gateway attaches to one VPC at a time.+ return _error("Resource.AlreadyAssociated",+ f"resource {igw_id} is already attached to network "+ f"{igw['Attachments'][0]['VpcId']}", 400)igw["Attachments"] = [{"VpcId": vpc_id, "State": "available"}]return _xml(200, "AttachInternetGatewayResponse", "<return>true</return>")diff --git a/ministack/services/eventbridge.py b/ministack/services/eventbridge.pyindex 2b1df0e4..deba4c36 100644--- a/ministack/services/eventbridge.py+++ b/ministack/services/eventbridge.py@@ -460,10 +460,11 @@ def _update_event_bus(data):bus["LastModifiedTime"] = now- return json_response({- "EventBusArn": bus["Arn"],- "LastModifiedTime": bus["LastModifiedTime"],- })+ out = {"Arn": bus["Arn"], "Name": bus["Name"]}+ for k in ("Description", "KmsKeyIdentifier", "DeadLetterConfig", "LogConfig"):+ if k in bus:+ out[k] = bus[k]+ return json_response(out)# ---------------------------------------------------------------------------diff --git a/ministack/services/inspector2.py b/ministack/services/inspector2.pyindex c159775d..c7222b70 100644--- a/ministack/services/inspector2.py+++ b/ministack/services/inspector2.py@@ -6,6 +6,7 @@ REST-JSON API with deterministic stub vulnerability findings."""import copy+import datetimeimport jsonimport loggingimport time@@ -31,8 +32,9 @@ _tags = AccountScopedDict()_filters = AccountRegionScopedDict()-def _now_iso():- return time.strftime("%Y-%m-%dT%H:%M:%S+00:00", time.gmtime())+def _now():+ # rest-json timestamps without a timestampFormat are epoch seconds+ return int(time.time())def _finding_arn(acct_id, finding_id):@@ -266,7 +268,7 @@ def _build_finding(pkg, resource_type, resource_id, account_id):"imageHash": "sha256:" + uuid.uuid4().hex,"architecture": pkg.get("arch", ""),"platform": "linux",- "pushedAt": _now_iso(),+ "pushedAt": _now(),}}elif resource_type == "AWS_LAMBDA_FUNCTION":@@ -278,7 +280,7 @@ def _build_finding(pkg, resource_type, resource_id, account_id):"version": "$LATEST","executionRoleArn": f"arn:aws:iam::{account_id}:role/service-role/test-role","packageType": "ZIP",- "lastModifiedAt": _now_iso(),+ "lastModifiedAt": _now(),}}elif resource_type == "AWS_EC2_INSTANCE":@@ -287,7 +289,7 @@ def _build_finding(pkg, resource_type, resource_id, account_id):"type": "t3.medium","imageId": "ami-0abcdef1234567890","platform": "linux",- "launchedAt": _now_iso(),+ "launchedAt": _now(),}}@@ -300,9 +302,9 @@ def _build_finding(pkg, resource_type, resource_id, account_id):"description": f"{pkg['vulnId']} — {pkg['cwe']} — in {pkg['name']}@{pkg['version']}","severity": pkg["severity"],"status": "ACTIVE",- "firstObservedAt": _now_iso(),- "lastObservedAt": _now_iso(),- "updatedAt": _now_iso(),+ "firstObservedAt": _now(),+ "lastObservedAt": _now(),+ "updatedAt": _now(),"inspectorScore": round(risk, 2),"fixAvailable": FIX_STATE_MAP.get(fix, "NO"),"exploitAvailable": "NO" if pkg["severity"] != "CRITICAL" else "YES",@@ -321,8 +323,8 @@ def _build_finding(pkg, resource_type, resource_id, account_id):"source": "NVD","sourceUrl": f"https://nvd.nist.gov/vuln/detail/{pkg['vulnId']}","vendorSeverity": pkg["severity"],- "vendorCreatedAt": _now_iso(),- "vendorUpdatedAt": _now_iso(),+ "vendorCreatedAt": _now(),+ "vendorUpdatedAt": _now(),"referenceUrls": [f"https://nvd.nist.gov/vuln/detail/{pkg['vulnId']}"],"relatedVulnerabilities": [],"cvss": [@@ -403,7 +405,7 @@ def _run_scan(account_id):for r in f["resources"]:resources.add((r["type"], r["id"]))- timestamp = _now_iso()+ timestamp = _now()_findings[account_id] = findings_scan_history[account_id] = {"lastScanAt": timestamp,@@ -420,7 +422,7 @@ def _run_scan(account_id):"resourceId": rid,"resourceType": rtype,"scanType": "PACKAGE",- "scanStatus": {"code": "ACTIVE", "reason": "INITIAL_SCAN_COMPLETE"},+ "scanStatus": {"statusCode": "ACTIVE", "reason": "SUCCESSFUL"},"lastScannedAt": timestamp,"scanMode": "EC2_AGENTLESS",}@@ -680,7 +682,7 @@ def _list_findings(data, account_id):sev_order = {"CRITICAL": 0, "HIGH": 1, "MEDIUM": 2, "LOW": 3, "INFORMATIONAL": 4, "UNTRIAGED": 5}filtered.sort(key=lambda f: sev_order.get(f.get("severity", ""), 99), reverse=(order == "DESC"))elif field == "FIRST_OBSERVED_AT":- filtered.sort(key=lambda f: f.get("firstObservedAt", ""), reverse=(order == "DESC"))+ filtered.sort(key=lambda f: f.get("firstObservedAt", 0), reverse=(order == "DESC"))elif field == "INSPECTOR_SCORE":filtered.sort(key=lambda f: f.get("inspectorScore", 0), reverse=(order == "DESC"))@@ -705,7 +707,7 @@ def _list_coverage(data, account_id):if scan_status_filter:filtered = []for cov in all_coverage:- status_code = cov.get("scanStatus", {}).get("code", "")+ status_code = cov.get("scanStatus", {}).get("statusCode", "")for cond in scan_status_filter:comparison = cond.get("comparison", "EQUALS")value = cond.get("value", "")@@ -734,7 +736,7 @@ def _list_coverage_statistics(data, account_id):for cov in all_coverage:rt = cov.get("resourceType", "UNKNOWN")- sc = cov.get("scanStatus", {}).get("code", "UNKNOWN")+ sc = cov.get("scanStatus", {}).get("statusCode", "UNKNOWN")counts_by_resource[rt] = counts_by_resource.get(rt, 0) + 1counts_by_scan[sc] = counts_by_scan.get(sc, 0) + 1@@ -812,20 +814,20 @@ def _search_vulnerabilities(data, account_id):"source": pvd.get("source", ""),"description": f.get("description", ""),"vendorSeverity": pvd.get("vendorSeverity", ""),- "vendorCreatedAt": pvd.get("vendorCreatedAt", _now_iso()),- "vendorUpdatedAt": pvd.get("vendorUpdatedAt", _now_iso()),+ "vendorCreatedAt": pvd.get("vendorCreatedAt", _now()),+ "vendorUpdatedAt": pvd.get("vendorUpdatedAt", _now()),"sourceUrl": pvd.get("sourceUrl", ""),"referenceUrls": pvd.get("referenceUrls", []),"relatedVulnerabilities": pvd.get("relatedVulnerabilities", []),"atigData": {- "firstSeen": pvd.get("vendorCreatedAt", _now_iso()),- "lastSeen": pvd.get("vendorUpdatedAt", _now_iso()),+ "firstSeen": pvd.get("vendorCreatedAt", _now()),+ "lastSeen": pvd.get("vendorUpdatedAt", _now()),},"cvss4": {"baseScore": base_score, "scoringVector": scoring_vector},"cvss3": {"baseScore": base_score, "scoringVector": scoring_vector},"cvss2": {"baseScore": 0.0, "scoringVector": ""},- "cisaData": {"dateAdded": _now_iso(), "dateDue": _now_iso(), "action": ""},- "exploitObserved": {"lastSeen": _now_iso(), "firstSeen": _now_iso()},+ "cisaData": {"dateAdded": _now(), "dateDue": _now(), "action": ""},+ "exploitObserved": {"lastSeen": _now(), "firstSeen": _now()},"detectionPlatforms": [],"epss": {"score": 0.0},"cwes": [],@@ -925,15 +927,19 @@ def _create_filter(data, account_id):if name in _filters[account_id]:return error_response_json("ConflictException", f"Filter {name} already exists", 409)+ now = _now()filt = {"arn": _filter_arn(account_id, name),+ "ownerId": account_id,"name": name,"action": action,- "findingCriteria": filter_criteria,+ "criteria": filter_criteria,"description": description,+ "createdAt": now,+ "updatedAt": now,}_filters[account_id][name] = filt- return json_response(filt)+ return json_response({"arn": filt["arn"]})def _list_filters(data, account_id):@@ -1240,6 +1246,45 @@ def _restore_state(data):):_restore_regional_bucket(store, data.get(state_key, {}))_restore_account_bucket(_tags, data.get("tags", {}))+ for store in (_findings, _coverage, _scan_history, _filters):+ for value in store._data.values():+ _migrate_legacy_shapes(value)+++_TIMESTAMP_KEYS = frozenset({+ "pushedAt", "lastModifiedAt", "launchedAt", "firstObservedAt", "lastObservedAt",+ "updatedAt", "createdAt", "vendorCreatedAt", "vendorUpdatedAt", "lastScanAt",+ "lastScannedAt", "firstSeen", "lastSeen", "dateAdded", "dateDue",+})+++def _migrate_legacy_shapes(node):+ """State saved before timestamps were epoch seconds, ``scanStatus`` used+ ``statusCode`` and filters kept ``criteria``, ``ownerId`` and timestamps."""+ if isinstance(node, list):+ for item in node:+ _migrate_legacy_shapes(item)+ return+ if not isinstance(node, dict):+ return+ for key, value in list(node.items()):+ if key in _TIMESTAMP_KEYS and isinstance(value, str):+ try:+ node[key] = int(datetime.datetime.fromisoformat(value).timestamp())+ except ValueError:+ pass+ else:+ _migrate_legacy_shapes(value)+ status = node.get("scanStatus")+ if isinstance(status, dict) and "code" in status:+ status["statusCode"] = status.pop("code")+ if status.get("reason") == "INITIAL_SCAN_COMPLETE":+ status["reason"] = "SUCCESSFUL"+ if "findingCriteria" in node and "arn" in node:+ node["criteria"] = node.pop("findingCriteria")+ node.setdefault("ownerId", node["arn"].split(":")[4])+ node.setdefault("createdAt", _now())+ node.setdefault("updatedAt", node["createdAt"])def _restore_regional_bucket(store, restored):diff --git a/ministack/services/iot.py b/ministack/services/iot.pyindex 7410c240..dced825d 100644--- a/ministack/services/iot.py+++ b/ministack/services/iot.py@@ -2907,7 +2907,7 @@ async def _publish_event(account_id: str, region: str, topic: str, event: dict)def _registry_event(config_type: str, topic: str, event_type: str, operation: str, fields: dict,- event_id: str | None = None,+ event_id: str | None = None, with_account: bool = True,) -> None:"""Queue ``$aws/events/{topic}`` when ``config_type`` is enabled for the request's account and region."""pending = _pending_events.get()@@ -2919,7 +2919,7 @@ def _registry_event("eventId": event_id or uuid.uuid4().hex,"timestamp": int(time.time() * 1000),"operation": operation,- "accountId": get_account_id(),+ **({"accountId": get_account_id()} if with_account else {}),**fields,}))@@ -2946,7 +2946,7 @@ def _thing_events(operation: str, thing: dict, old_type: str | None) -> None:f"thingTypeAssociation/thing/{name}/thingType/{type_name}/{change.lower()}","THING_TYPE_ASSOCIATION_EVENT", change,{"thingId": thing["thingId"], "thingName": name, "thingTypeName": type_name},- event_id,+ event_id, with_account=False,)diff --git a/ministack/services/lambda_svc.py b/ministack/services/lambda_svc.pyindex 4e8b40b3..2db5fcae 100644--- a/ministack/services/lambda_svc.py+++ b/ministack/services/lambda_svc.py@@ -5640,8 +5640,13 @@ def _execute_function_local(func: dict, event: dict) -> dict:if not endpoint:# Subprocess runs on the same host as ministack — point it at# ourselves so boto3 calls land back here, not at real AWS.+ from ministack.core import tls as _tls+gateway_port = os.environ.get("GATEWAY_PORT", "4566")- endpoint = f"http://{_MINISTACK_HOST}:{gateway_port}"+ scheme = "https" if _tls.use_ssl_enabled() else "http"+ endpoint = f"{scheme}://{_MINISTACK_HOST}:{gateway_port}"+ if scheme == "https":+ _tls.trust_gateway_cert(env)if endpoint:env["AWS_ENDPOINT_URL"] = endpointenv.update(env_vars)@@ -5760,6 +5765,11 @@ def _publish_version(name: str, data: dict):404,)func = _functions[name]+ # "Lambda doesn't publish a version if the function's configuration and code+ # haven't changed since the last version": the latest version comes back.+ latest = max(func["versions"], key=int, default=None)+ if latest and func["versions"][latest].get("function_revision") == func["config"].get("RevisionId"):+ return json_response(func["versions"][latest]["config"], 201)ver_num = func["next_version"]func["next_version"] = ver_num + 1diff --git a/ministack/services/mq.py b/ministack/services/mq.pyindex 0c4789a6..5785c1b4 100644--- a/ministack/services/mq.py+++ b/ministack/services/mq.py@@ -726,7 +726,7 @@ def _list_broker_instance_options(query_params: dict) -> tuple:"engineType": eng,"hostInstanceType": host,"storageType": stor,- "supportedEngineVersions": [{"name": v} for v in cfg["versions"]],+ "supportedEngineVersions": list(cfg["versions"]),"supportedDeploymentModes": list(cfg["deployment_modes"]),})diff --git a/ministack/services/rds.py b/ministack/services/rds.pyindex b093e291..20b6ca36 100644--- a/ministack/services/rds.py+++ b/ministack/services/rds.py@@ -2551,8 +2551,8 @@ def _get_docker():def _in_container():- """Docker's and Podman's markers, as lambda_svc._running_in_container checks first."""- return os.path.exists("/.dockerenv") or os.path.exists("/run/.containerenv")+ from ministack.services.lambda_svc import _running_in_container+ return _running_in_container()def _get_ministack_network(docker_client):@@ -7803,7 +7803,7 @@ def _describe_global_clusters(p):gcs = snapshotsmembers_xml = "".join(- f"<GlobalCluster>{_global_cluster_xml(gc)}</GlobalCluster>" for gc in gcs+ f"<GlobalClusterMember>{_global_cluster_xml(gc)}</GlobalClusterMember>" for gc in gcs)return _xml(200, "DescribeGlobalClustersResponse",f"<DescribeGlobalClustersResult><GlobalClusters>{members_xml}</GlobalClusters></DescribeGlobalClustersResult>")diff --git a/ministack/services/servicediscovery.py b/ministack/services/servicediscovery.pyindex 13e01702..af91c226 100644--- a/ministack/services/servicediscovery.py+++ b/ministack/services/servicediscovery.py@@ -353,6 +353,9 @@ def _delete_namespace(data):return error_response_json("InvalidInput", "Id is required", 400)if ns_id not in _namespaces:return error_response_json("NamespaceNotFound", "Namespace not found", 404)+ if any(s.get("NamespaceId") == ns_id for s in _services.values()):+ return error_response_json(+ "ResourceInUse", "Namespace has associated services; delete the services before deleting the namespace", 400)namespace = _namespaces.pop(ns_id)_resource_tags.pop(namespace.get("Arn", ""), None)diff --git a/ministack/services/ses.py b/ministack/services/ses.pyindex 3825cf16..1e3d2b55 100644--- a/ministack/services/ses.py+++ b/ministack/services/ses.py@@ -425,15 +425,17 @@ def _verify_domain_identity(params):f"</VerifyDomainIdentityResult>")+def _dkim_tokens(domain):+ """The three Easy DKIM tokens for a domain identity, stable per domain."""+ return [hashlib.md5(f"{domain}-dkim-{i}".encode()).hexdigest()[:32] for i in range(3)]++def _verify_domain_dkim(params):domain = _p(params, "Domain")if domain not in _identities:_identities[domain] = _make_identity(domain, "Domain")- tokens = [- hashlib.md5(f"{domain}-dkim-{i}".encode()).hexdigest()[:32]- for i in range(3)- ]+ tokens = _dkim_tokens(domain)_identities[domain]["DkimEnabled"] = True_identities[domain]["DkimTokens"] = tokens_identities[domain]["DkimVerificationStatus"] = "Success"diff --git a/ministack/services/ses_v2.py b/ministack/services/ses_v2.pyindex 305e290a..6f234782 100644--- a/ministack/services/ses_v2.py+++ b/ministack/services/ses_v2.py@@ -15,7 +15,6 @@ Email templates live in the v1 store, so either API version sees the other's.import base64import copy-import hashlibimport jsonimport loggingimport os@@ -34,6 +33,7 @@ from ministack.core.responses import ()from ministack.services.ses import (_build_mime_message,+ _dkim_tokens,_parse_raw_mime,_render_template,_restore_regional_store,@@ -121,10 +121,7 @@ def _easy_dkim_attributes(identity, identity_type, signing_attributes):byodkim = any(signing_attributes.get(k) for k in ("DomainSigningPrivateKey", "DomainSigningSelector"))if identity_type != "DOMAIN" or byodkim:return {"SigningEnabled": False, "Status": "NOT_STARTED", "Tokens": []}- tokens = [- hashlib.md5(f"{identity}-dkim-{i}".encode()).hexdigest()[:32]- for i in range(3)- ]+ tokens = _dkim_tokens(identity)return {"SigningEnabled": False,"SigningAttributesOrigin": "AWS_SES",diff --git a/ministack/services/stepfunctions.py b/ministack/services/stepfunctions.pyindex 4e77415e..2b20adad 100644--- a/ministack/services/stepfunctions.py+++ b/ministack/services/stepfunctions.py@@ -1239,8 +1239,8 @@ def _test_state(data):result["nextState"] = next_stateelif state_type == "Succeed":- output = _apply_input_path(state_def, input_data)- output = _apply_output_path(state_def, output)+ output = _apply_input_path(state_def, input_data, ctx)+ output = _apply_output_path(state_def, output, ctx)result = {"status": "SUCCEEDED", "output": json.dumps(output)}elif state_type == "Fail":@@ -1251,11 +1251,11 @@ def _test_state(data):}elif state_type == "Task":- effective = _apply_input_path(state_def, input_data)+ effective = _apply_input_path(state_def, input_data, ctx)effective = _apply_parameters(state_def, effective, ctx)if inspection_level in ("DEBUG", "TRACE"):- inspection_data["afterInputPath"] = json.dumps(_apply_input_path(state_def, input_data))+ inspection_data["afterInputPath"] = json.dumps(_apply_input_path(state_def, input_data, ctx))inspection_data["afterParameters"] = json.dumps(effective)# Mock support@@ -1310,7 +1310,7 @@ def _test_state(data):mock_result = mock["result"]task_result = _apply_result_selector(state_def, mock_result)output = _apply_result_path(state_def, input_data, task_result)- output = _apply_output_path(state_def, output)+ output = _apply_output_path(state_def, output, ctx)result = {"status": "SUCCEEDED", "output": json.dumps(output)}next_state = _next_or_end(state_def)if next_state:@@ -1331,7 +1331,7 @@ def _test_state(data):if inspection_level in ("DEBUG", "TRACE"):inspection_data["afterResultPath"] = json.dumps(output)- output = _apply_output_path(state_def, output)+ output = _apply_output_path(state_def, output, ctx)result = {"status": "SUCCEEDED", "output": json.dumps(output)}next_state = _next_or_end(state_def)if next_state:@@ -1532,8 +1532,8 @@ def _run_execution(exec_arn):})if state_type == "Succeed":- current_input = _apply_input_path(state_def, current_input)- current_input = _apply_output_path(state_def, current_input)+ current_input = _apply_input_path(state_def, current_input, ctx)+ current_input = _apply_output_path(state_def, current_input, ctx)_add_event(execution, "SucceedStateExited", {"stateExitedEventDetails": {"name": current_name,@@ -1620,13 +1620,13 @@ def _execute_pass(state_def, raw_input, ctx=None):_apply_state_assign(state_def, raw_input, ctx, result=output)return output, _next_or_end(state_def)- effective = _apply_input_path(state_def, raw_input)+ effective = _apply_input_path(state_def, raw_input, ctx)effective = _apply_parameters(state_def, effective, ctx)result = state_def.get("Result", effective)result = _apply_result_selector(state_def, result)output = _apply_result_path(state_def, raw_input, result)- output = _apply_output_path(state_def, output)+ output = _apply_output_path(state_def, output, ctx)return output, _next_or_end(state_def)@@ -1670,7 +1670,7 @@ def _execute_task(state_def, raw_input, execution, ctx):else:result = _apply_result_selector(state_def, mock_result)output = _apply_result_path(state_def, raw_input, result)- output = _apply_output_path(state_def, output)+ output = _apply_output_path(state_def, output, ctx)return output, _next_or_end(state_def)if is_callback:@@ -1678,7 +1678,7 @@ def _execute_task(state_def, raw_input, execution, ctx):effective = Noneif query_language != "JSONata":- effective = _apply_input_path(state_def, raw_input)+ effective = _apply_input_path(state_def, raw_input, ctx)effective = _apply_parameters(state_def, effective, ctx)retriers = state_def.get("Retry", [])@@ -1728,7 +1728,7 @@ def _execute_task(state_def, raw_input, execution, ctx):else:result = _apply_result_selector(state_def, task_result)output = _apply_result_path(state_def, raw_input, result)- output = _apply_output_path(state_def, output)+ output = _apply_output_path(state_def, output, ctx)return output, _next_or_end(state_def)except _ExecutionError as err:@@ -2003,15 +2003,15 @@ def _execute_choice(state_def, raw_input, ctx=None):raise _ExecutionError("States.NoChoiceMatched","No choice rule matched and no Default")- effective = _apply_input_path(state_def, raw_input)+ effective = _apply_input_path(state_def, raw_input, ctx)for choice in state_def.get("Choices", []):if _evaluate_rule(choice, effective, ctx):- return _apply_output_path(state_def, effective), choice["Next"]+ return _apply_output_path(state_def, effective, ctx), choice["Next"]default = state_def.get("Default")if default:- return _apply_output_path(state_def, effective), default+ return _apply_output_path(state_def, effective, ctx), defaultraise _ExecutionError("States.NoChoiceMatched","No choice rule matched and no Default")@@ -2031,7 +2031,7 @@ def _evaluate_jsonata_choice_rule(rule, raw_input, ctx):return _truthy(condition)-def _resolve_choice_path(path, data, ctx):+def _resolve_path_or_ctx(path, data, ctx):if path.startswith("$$."):return _resolve_ctx_path(path, ctx or {})return _resolve_path(path, data)@@ -2048,7 +2048,7 @@ def _evaluate_rule(rule, data, ctx=None):variable = rule.get("Variable")if not variable:return False- value = _resolve_choice_path(variable, data, ctx)+ value = _resolve_path_or_ctx(variable, data, ctx)# --- type checks ---if "IsPresent" in rule:@@ -2068,7 +2068,7 @@ def _evaluate_rule(rule, data, ctx=None):if "StringEquals" in rule:return value == rule["StringEquals"]if "StringEqualsPath" in rule:- return value == _resolve_choice_path(rule["StringEqualsPath"], data, ctx)+ return value == _resolve_path_or_ctx(rule["StringEqualsPath"], data, ctx)if "StringLessThan" in rule:return isinstance(value, str) and value < rule["StringLessThan"]if "StringGreaterThan" in rule:@@ -2085,7 +2085,7 @@ def _evaluate_rule(rule, data, ctx=None):if "NumericEquals" in rule:return _is_num(value) and value == rule["NumericEquals"]if "NumericEqualsPath" in rule:- return _is_num(value) and value == _resolve_choice_path(rule["NumericEqualsPath"], data, ctx)+ return _is_num(value) and value == _resolve_path_or_ctx(rule["NumericEqualsPath"], data, ctx)if "NumericLessThan" in rule:return _is_num(value) and value < rule["NumericLessThan"]if "NumericGreaterThan" in rule:@@ -2095,23 +2095,23 @@ def _evaluate_rule(rule, data, ctx=None):if "NumericGreaterThanEquals" in rule:return _is_num(value) and value >= rule["NumericGreaterThanEquals"]if "NumericLessThanPath" in rule:- rhs = _resolve_choice_path(rule["NumericLessThanPath"], data, ctx)+ rhs = _resolve_path_or_ctx(rule["NumericLessThanPath"], data, ctx)return _is_num(value) and _is_num(rhs) and value < rhsif "NumericGreaterThanPath" in rule:- rhs = _resolve_choice_path(rule["NumericGreaterThanPath"], data, ctx)+ rhs = _resolve_path_or_ctx(rule["NumericGreaterThanPath"], data, ctx)return _is_num(value) and _is_num(rhs) and value > rhsif "NumericLessThanEqualsPath" in rule:- rhs = _resolve_choice_path(rule["NumericLessThanEqualsPath"], data, ctx)+ rhs = _resolve_path_or_ctx(rule["NumericLessThanEqualsPath"], data, ctx)return _is_num(value) and _is_num(rhs) and value <= rhsif "NumericGreaterThanEqualsPath" in rule:- rhs = _resolve_choice_path(rule["NumericGreaterThanEqualsPath"], data, ctx)+ rhs = _resolve_path_or_ctx(rule["NumericGreaterThanEqualsPath"], data, ctx)return _is_num(value) and _is_num(rhs) and value >= rhs# --- boolean ---if "BooleanEquals" in rule:return value is rule["BooleanEquals"] or value == rule["BooleanEquals"]if "BooleanEqualsPath" in rule:- return value == _resolve_choice_path(rule["BooleanEqualsPath"], data, ctx)+ return value == _resolve_path_or_ctx(rule["BooleanEqualsPath"], data, ctx)# --- timestamp ---for op, cmp_fn in [("TimestampEquals", lambda a, b: a == b),@@ -2131,7 +2131,7 @@ def _evaluate_rule(rule, data, ctx=None):# ---------------------------------------------------------------------------def _execute_wait(state_def, raw_input, ctx=None):- effective = _apply_input_path(state_def, raw_input)+ effective = _apply_input_path(state_def, raw_input, ctx)if "Seconds" in state_def:_scaled_sleep(state_def["Seconds"])@@ -2146,7 +2146,7 @@ def _execute_wait(state_def, raw_input, ctx=None):if isinstance(ts_str, str):_sleep_until(ts_str)- output = _apply_output_path(state_def, effective)+ output = _apply_output_path(state_def, effective, ctx)return output, _next_or_end(state_def)@@ -2171,7 +2171,7 @@ def _sleep_until(iso_ts):# ---------------------------------------------------------------------------def _execute_parallel(state_def, raw_input, execution, ctx):- effective = _apply_input_path(state_def, raw_input)+ effective = _apply_input_path(state_def, raw_input, ctx)effective = _apply_parameters(state_def, effective, ctx)branches = state_def.get("Branches", [])@@ -2212,7 +2212,7 @@ def _execute_parallel(state_def, raw_input, execution, ctx):result = _apply_result_selector(state_def, results)output = _apply_result_path(state_def, raw_input, result)- output = _apply_output_path(state_def, output)+ output = _apply_output_path(state_def, output, ctx)return output, _next_or_end(state_def)@@ -2223,10 +2223,10 @@ def _execute_parallel(state_def, raw_input, execution, ctx):def _execute_map(state_def, raw_input, execution, ctx):# No _apply_parameters here: on a Map, Parameters is the deprecated ItemSelector spelling and# is applied per item below -- and ItemsPath must resolve against the untransformed input- effective = _apply_input_path(state_def, raw_input)+ effective = _apply_input_path(state_def, raw_input, ctx)items_path = state_def.get("ItemsPath", "$")- items = _resolve_path(items_path, effective)+ items = _resolve_path_or_ctx(items_path, effective, ctx)if not isinstance(items, list):items = [items]@@ -2272,7 +2272,7 @@ def _execute_map(state_def, raw_input, execution, ctx):result = _apply_result_selector(state_def, results)output = _apply_result_path(state_def, raw_input, result)- output = _apply_output_path(state_def, output)+ output = _apply_output_path(state_def, output, ctx)return output, _next_or_end(state_def)@@ -2295,7 +2295,7 @@ def _run_sub_machine(states, start_at, input_data, execution, ctx):if state_type == "Succeed":return _apply_output_path(state_def,- _apply_input_path(state_def, current_input))+ _apply_input_path(state_def, current_input, ctx), ctx)if state_type == "Fail":raise _ExecutionError(state_def.get("Error", "States.Fail"),@@ -2328,18 +2328,18 @@ def _run_sub_machine(states, start_at, input_data, execution, ctx):# Path / Parameter processing# ===================================================================-def _apply_input_path(state_def, data):+def _apply_input_path(state_def, data, ctx=None):ip = state_def.get("InputPath", "$")if ip is None:return {}- return _resolve_path(ip, data)+ return _resolve_path_or_ctx(ip, data, ctx)-def _apply_output_path(state_def, data):+def _apply_output_path(state_def, data, ctx=None):op = state_def.get("OutputPath", "$")if op is None:return {}- return _resolve_path(op, data)+ return _resolve_path_or_ctx(op, data, ctx)def _apply_parameters(state_def, data, ctx=None):@@ -3714,7 +3714,7 @@ _XML_LIST_WRAPPER_TAGS = frozenset({"ReadReplicaDBClusterIdentifiers", "DBSecurityGroups","OptionGroupMemberships", "OptionGroupsList", "StatusInfos", "DomainMemberships","AssociatedRoles", "TagList", "ProcessorFeatures",- "EnabledCloudwatchLogsExports", "GlobalClusterMembers",+ "EnabledCloudwatchLogsExports", "GlobalClusterMembers", "GlobalClusters","DBParameterGroups", "DBInstances", "DBClusters", "Readers","SupportedNetworkTypes","Roles", "Users", "Groups", "Policies", "AttachedPolicies", "PolicyNames",diff --git a/tests/test_apigatewayv2.py b/tests/test_apigatewayv2.pyindex 732181dd..4e20c1d2 100644--- a/tests/test_apigatewayv2.py+++ b/tests/test_apigatewayv2.py@@ -1025,6 +1025,18 @@ def test_apigw_execute_no_route(apigw):except _urlerr.HTTPError as e:assert e.code == 404assert e.read() == b'{"message":"Not Found"}'+ # No stage matches and there is no $default stage: the same body.+ staged = apigw.create_api(Name="no-stage-api", ProtocolType="HTTP")["ApiId"]+ apigw.create_stage(ApiId=staged, StageName="prod")+ req = _urlreq.Request(f"http://{staged}.execute-api.localhost:{_EXECUTE_PORT}/dev/x", method="GET")+ req.add_header("Host", f"{staged}.execute-api.localhost:{_EXECUTE_PORT}")+ try:+ _urlreq.urlopen(req)+ assert False, "Expected 404"+ except _urlerr.HTTPError as e:+ assert e.code == 404+ assert e.read() == b'{"message":"Not Found"}'+ apigw.delete_api(ApiId=staged)apigw.delete_api(ApiId=api_id)def test_apigw_execute_default_route(apigw, lam):@@ -4300,22 +4312,28 @@ def test_apigwv2_authorizer_missing_identity_source_401s_without_invoking(apigw,_v2_auth_delete_queue(sqs, qname)-def test_apigwv2_authorizer_context_identity_source_still_invokes(apigw, lam, sqs):- """A $context.* identity source, which MiniStack does not model, is not a missing source: uncached, the- authorizer is still invoked."""[email protected]("source,ttl,calls,invocations", [+ ("$context.identity.sourceIp", 0, 1, 1),+ # "To cache responses per route, add $context.routeKey to your authorizer's identity sources."+ ("$context.routeKey", 300, 2, 1),+])+def test_apigwv2_authorizer_context_identity_source_still_invokes(apigw, lam, sqs, source, ttl,+ calls, invocations):+ """A $context.* identity source is resolved from the request, so it is never missing and,+ cached, keys the authorizer cache."""qname = _v2_auth_counter_queue(sqs)backend = _v2_auth_make_lambda(lam, "be", _V2_AUTH_ECHO_BACKEND)authz = _v2_auth_make_lambda(lam, "pol", _v2_auth_policy_authorizer_code(qname))api_id, _ = _v2_auth_build_api(apigw, authz, backend,dict(Name="pol", AuthorizerPayloadFormatVersion="2.0",- IdentitySource=["$context.identity.sourceIp"],- AuthorizerResultTtlInSeconds=0),+ IdentitySource=[source], AuthorizerResultTtlInSeconds=ttl),)try:- status, _body = _v2_auth_http(_v2_auth_execute_url(api_id, "test", "secure"))- assert status != 401- assert _v2_auth_count(sqs, qname) == 1, "the authorizer Lambda must be invoked"+ for _ in range(calls):+ status, _body = _v2_auth_http(_v2_auth_execute_url(api_id, "test", "secure"))+ assert status != 401+ assert _v2_auth_count(sqs, qname) == invocationsfinally:_v2_auth_drop_api(apigw, api_id)_v2_auth_drop_lambda(lam, backend)diff --git a/tests/test_cfn.py b/tests/test_cfn.pyindex a4b0703d..3e75a428 100644--- a/tests/test_cfn.py+++ b/tests/test_cfn.py@@ -8556,6 +8556,62 @@ def test_cfn_codebuild_project_basic(cfn, codebuild):assert len(result["projects"]) == 0+def test_cfn_codebuild_project_uses_api_member_names(cfn, codebuild):+ """Source, Artifacts and Environment are stored with the CodeBuild API's+ member names, on create and on update: the template's BuildSpec is the+ API's buildspec, and the other PascalCase members are camelCase."""+ buildspec = "version: 0.2\nphases:\n build:\n commands:\n - echo hi\n"++ def template(image):+ return json.dumps({+ "AWSTemplateFormatVersion": "2010-09-09",+ "Resources": {+ "Project": {+ "Type": "AWS::CodeBuild::Project",+ "Properties": {+ "Name": "cfn-cb-api-names",+ "Source": {"Type": "NO_SOURCE", "BuildSpec": buildspec},+ "Artifacts": {"Type": "NO_ARTIFACTS"},+ "Environment": {+ "Type": "LINUX_CONTAINER",+ "Image": image,+ "ComputeType": "BUILD_GENERAL1_SMALL",+ "PrivilegedMode": True,+ "EnvironmentVariables": [+ {"Name": "STAGE", "Value": "test", "Type": "PLAINTEXT"},+ ],+ },+ "ServiceRole": "arn:aws:iam::000000000000:role/codebuild-role",+ },+ }+ },+ })++ cfn.create_stack(StackName="cfn-cb-api-names", TemplateBody=template("aws/codebuild/standard:7.0"))+ try:+ assert _wait_stack(cfn, "cfn-cb-api-names")["StackStatus"] == "CREATE_COMPLETE"+ project = codebuild.batch_get_projects(names=["cfn-cb-api-names"])["projects"][0]+ assert project["source"]["type"] == "NO_SOURCE"+ assert project["source"]["buildspec"] == buildspec+ assert project["artifacts"]["type"] == "NO_ARTIFACTS"+ assert project["environment"]["type"] == "LINUX_CONTAINER"+ assert project["environment"]["image"] == "aws/codebuild/standard:7.0"+ assert project["environment"]["computeType"] == "BUILD_GENERAL1_SMALL"+ assert project["environment"]["privilegedMode"] is True+ assert project["environment"]["environmentVariables"] == [+ {"name": "STAGE", "value": "test", "type": "PLAINTEXT"},+ ]++ cfn.update_stack(StackName="cfn-cb-api-names", TemplateBody=template("aws/codebuild/standard:6.0"))+ assert _wait_stack(cfn, "cfn-cb-api-names")["StackStatus"] == "UPDATE_COMPLETE"+ project = codebuild.batch_get_projects(names=["cfn-cb-api-names"])["projects"][0]+ assert project["environment"]["image"] == "aws/codebuild/standard:6.0"+ assert project["source"]["buildspec"] == buildspec+ finally:+ cfn.delete_stack(StackName="cfn-cb-api-names")+ _wait_stack(cfn, "cfn-cb-api-names")++def test_cfn_codebuild_project_auto_name(cfn, codebuild):"""When Name is omitted, _physical_name() generates one."""template = {@@ -17941,6 +17997,32 @@ def _cfn_appsync_members_template(name, api_props, oidc):})+def test_cfn_ecs_task_definition_keeps_omitted_fields_omitted(cfn, ecs):+ """Cpu, Memory and RequiresCompatibilities are stored only when the template sets them."""+ suffix = _uuid_mod.uuid4().hex[:8]+ stack_name = f"cfn-ecs-td-{suffix}"+ family = f"cfn-ecs-td-{suffix}"+ container = [{"Name": "app", "Image": "nginx:latest", "Memory": 128}]+ template = json.dumps({"Resources": {+ "Bare": {"Type": "AWS::ECS::TaskDefinition",+ "Properties": {"Family": family, "ContainerDefinitions": container}},+ "Sized": {"Type": "AWS::ECS::TaskDefinition",+ "Properties": {"Family": f"{family}-f", "ContainerDefinitions": container,+ "Cpu": "512", "Memory": "1024",+ "RequiresCompatibilities": ["FARGATE"], "NetworkMode": "awsvpc"}},+ }})+ try:+ cfn.create_stack(StackName=stack_name, TemplateBody=template)+ assert _wait_stack(cfn, stack_name)["StackStatus"] == "CREATE_COMPLETE"+ bare = ecs.describe_task_definition(taskDefinition=family)["taskDefinition"]+ assert not {"cpu", "memory", "requiresCompatibilities"} & set(bare)+ sized = ecs.describe_task_definition(taskDefinition=f"{family}-f")["taskDefinition"]+ assert (sized["cpu"], sized["memory"], sized["requiresCompatibilities"]) == (+ "512", "1024", ["FARGATE"])+ finally:+ _delete_cfn_test_stack(cfn, stack_name)++def test_cfn_ecs_cluster_settings_read_back_in_the_api_shape(cfn, ecs):"""ClusterSettings, DefaultCapacityProviderStrategy and Configuration read back in camelCase."""suffix = _uuid_mod.uuid4().hex[:8]@@ -28113,6 +28195,23 @@ def _cfn_igw_vpcs(ec2, igw_id):InternetGatewayIds=[igw_id])["InternetGateways"][0].get("Attachments", [])]+def test_cfn_ec2_gateway_attachment_keeps_the_first_vpc(cfn, ec2):+ """An internet gateway attaches to one VPC at a time. CloudFormation ignores the+ Resource.AlreadyAssociated of a second attachment, so the gateway keeps its first VPC."""+ stack_name = f"cfn-gwa-two-{_uuid_mod.uuid4().hex[:8]}"+ template = json.loads(_cfn_gateway_attachment_template(("InternetGatewayId", "Igw1")))+ template["Resources"]["Attach2"] = {+ "Type": "AWS::EC2::VPCGatewayAttachment", "DependsOn": "Attach",+ "Properties": {"VpcId": {"Ref": "Vpc2"}, "InternetGatewayId": {"Ref": "Igw1"}}}+ try:+ cfn.create_stack(StackName=stack_name, TemplateBody=json.dumps(template))+ assert _wait_stack(cfn, stack_name)["StackStatus"] == "CREATE_COMPLETE"+ vpc, igw1 = (_cfn_output(cfn, stack_name, k) for k in ("Vpc", "Igw1"))+ assert _cfn_igw_vpcs(ec2, igw1) == [vpc]+ finally:+ _delete_cfn_test_stack(cfn, stack_name)++def test_cfn_ec2_gateway_attachment_swaps_the_internet_gateway_in_place(cfn, ec2):"""A new InternetGatewayId moves the attachment under the same IGW|vpc id."""stack_name = f"cfn-gwa-igw-{_uuid_mod.uuid4().hex[:8]}"@@ -29598,3 +29697,751 @@ def test_describe_stack_resource_drifts_pagination(cfn):assert exc.value.response["Error"]["Code"] == "ValidationError"finally:_delete_cfn_test_stack(cfn, name)+++# ===========================================================================+# AWS::Glue::* resource types+# ===========================================================================++_GLUE_ROLE = "arn:aws:iam::000000000000:role/glue-cfn-role"+++def _glue_create(cfn, name, template):+ cfn.create_stack(StackName=name, TemplateBody=json.dumps(template))+ stack = _wait_stack(cfn, name)+ assert stack["StackStatus"] == "CREATE_COMPLETE", stack.get("StackStatusReason")+++def _glue_update(cfn, name, template):+ cfn.update_stack(StackName=name, TemplateBody=json.dumps(template))+ stack = _wait_stack(cfn, name)+ assert stack["StackStatus"] == "UPDATE_COMPLETE", stack.get("StackStatusReason")+++def _glue_outputs(cfn, name):+ stack = cfn.describe_stacks(StackName=name)["Stacks"][0]+ return {o["OutputKey"]: o["OutputValue"] for o in stack.get("Outputs", [])}+++def _glue_not_found(call):+ with pytest.raises(ClientError) as exc:+ call()+ assert exc.value.response["Error"]["Code"] == "EntityNotFoundException"+++def _glue_arn(sts, kind, name):+ account = sts.get_caller_identity()["Account"]+ return f"arn:aws:glue:us-east-1:{account}:{kind}/{name}"+++def _glue_data_lake(s, *, table_description="raw events", crawler_schedule=True,+ job_tags=True, trigger_description="nightly", partition_location="p1"):+ crawler = {+ "Name": f"crawler-{s}",+ "Role": _GLUE_ROLE,+ "DatabaseName": {"Ref": "Db"},+ "Targets": {"S3Targets": [{"Path": f"s3://lake-{s}/events/"}]},+ "Tags": {"team": "data"},+ }+ if crawler_schedule:+ crawler["Schedule"] = {"ScheduleExpression": "cron(0 2 * * ? *)"}+ job = {+ "Name": f"job-{s}",+ "Role": _GLUE_ROLE,+ "Command": {"Name": "pythonshell", "ScriptLocation": f"s3://lake-{s}/etl.py"},+ "DefaultArguments": {"--stage": "dev"},+ "MaxRetries": 1,+ }+ if job_tags:+ job["Tags"] = [{"Key": "owner", "Value": "etl"}]+ return {+ "Resources": {+ "Db": {+ "Type": "AWS::Glue::Database",+ "Properties": {+ "CatalogId": {"Ref": "AWS::AccountId"},+ "DatabaseInput": {"Name": f"lake_{s}", "Description": "data lake"},+ },+ },+ "Events": {+ "Type": "AWS::Glue::Table",+ "Properties": {+ "CatalogId": {"Ref": "AWS::AccountId"},+ "DatabaseName": {"Ref": "Db"},+ "TableInput": {+ "Name": "events",+ "Description": table_description,+ "TableType": "EXTERNAL_TABLE",+ "PartitionKeys": [{"Name": "dt", "Type": "string"}],+ "StorageDescriptor": {+ "Columns": [{"Name": "id", "Type": "string"}],+ "Location": f"s3://lake-{s}/events/",+ },+ },+ },+ },+ "Day": {+ "Type": "AWS::Glue::Partition",+ "Properties": {+ "CatalogId": {"Ref": "AWS::AccountId"},+ "DatabaseName": {"Ref": "Db"},+ "TableName": {"Ref": "Events"},+ "PartitionInput": {+ "Values": ["2026-10-01"],+ "StorageDescriptor": {"Location": f"s3://lake-{s}/events/{partition_location}/"},+ },+ },+ },+ "Jdbc": {+ "Type": "AWS::Glue::Connection",+ "Properties": {+ "CatalogId": {"Ref": "AWS::AccountId"},+ "ConnectionInput": {+ "Name": f"conn-{s}",+ "ConnectionType": "JDBC",+ "ConnectionProperties": {"JDBC_CONNECTION_URL": "jdbc:postgresql://db:5432/app"},+ },+ },+ },+ "Crawler": {"Type": "AWS::Glue::Crawler", "Properties": crawler},+ "Job": {"Type": "AWS::Glue::Job", "Properties": job},+ "Trigger": {+ "Type": "AWS::Glue::Trigger",+ "Properties": {+ "Name": f"trigger-{s}",+ "Type": "SCHEDULED",+ "Schedule": "cron(0 3 * * ? *)",+ "Description": trigger_description,+ "Actions": [{"JobName": {"Ref": "Job"}}],+ },+ },+ },+ "Outputs": {+ key: {"Value": {"Ref": key}}+ for key in ("Db", "Events", "Day", "Jdbc", "Crawler", "Job", "Trigger")+ } | {+ "JdbcName": {"Value": {"Fn::GetAtt": ["Jdbc", "Name"]}},+ "DayValues": {"Value": {"Fn::GetAtt": ["Day", "IdentifierPartitionInputValues"]}},+ },+ }+++def test_cfn_glue_data_lake_stack_create_and_delete(cfn, glue, sts):+ s = _uuid_mod.uuid4().hex[:8]+ stack = f"glue-lake-{s}"+ _glue_create(cfn, stack, _glue_data_lake(s))+ db, conn, crawler, job, trigger = f"lake_{s}", f"conn-{s}", f"crawler-{s}", f"job-{s}", f"trigger-{s}"++ out = _glue_outputs(cfn, stack)+ assert out["Db"] == db+ assert out["Events"] == "events"+ assert out["Jdbc"] == out["JdbcName"] == conn+ assert out["Crawler"] == crawler+ assert out["Job"] == job+ assert out["Trigger"] == trigger+ # The partition's Ref is its compound primary identifier joined with "|".+ account = sts.get_caller_identity()["Account"]+ assert out["Day"] == f"{account}|{db}|events|{out['DayValues']}"++ assert glue.get_database(Name=db)["Database"]["Description"] == "data lake"+ table = glue.get_table(DatabaseName=db, Name="events")["Table"]+ assert table["Description"] == "raw events"+ assert table["PartitionKeys"] == [{"Name": "dt", "Type": "string"}]+ partition = glue.get_partition(DatabaseName=db, TableName="events",+ PartitionValues=["2026-10-01"])["Partition"]+ assert partition["StorageDescriptor"]["Location"] == f"s3://lake-{s}/events/p1/"+ assert glue.get_connection(Name=conn)["Connection"]["ConnectionType"] == "JDBC"+ got_crawler = glue.get_crawler(Name=crawler)["Crawler"]+ assert got_crawler["DatabaseName"] == db+ assert got_crawler["Schedule"]["ScheduleExpression"] == "cron(0 2 * * ? *)"+ assert glue.get_job(JobName=job)["Job"]["Command"]["Name"] == "pythonshell"+ assert glue.get_trigger(Name=trigger)["Trigger"]["Actions"] == [{"JobName": job}]+ # Tags given as a map (crawler) and as a Tag list (job) both land.+ assert glue.get_tags(ResourceArn=_glue_arn(sts, "crawler", crawler))["Tags"] == {"team": "data"}+ assert glue.get_tags(ResourceArn=_glue_arn(sts, "job", job))["Tags"] == {"owner": "etl"}++ _delete_cfn_test_stack(cfn, stack)+ _glue_not_found(lambda: glue.get_database(Name=db))+ _glue_not_found(lambda: glue.get_table(DatabaseName=db, Name="events"))+ _glue_not_found(lambda: glue.get_connection(Name=conn))+ _glue_not_found(lambda: glue.get_crawler(Name=crawler))+ _glue_not_found(lambda: glue.get_job(JobName=job))+ _glue_not_found(lambda: glue.get_trigger(Name=trigger))+++def test_cfn_glue_update_in_place(cfn, glue, sts):+ s = _uuid_mod.uuid4().hex[:8]+ stack = f"glue-upd-{s}"+ _glue_create(cfn, stack, _glue_data_lake(s))+ db, crawler, job, trigger = f"lake_{s}", f"crawler-{s}", f"job-{s}", f"trigger-{s}"+ created = glue.get_table(DatabaseName=db, Name="events")["Table"]["CreateTime"]+ try:+ _glue_update(cfn, stack, _glue_data_lake(+ s, table_description="cleaned events", crawler_schedule=False, job_tags=False,+ trigger_description="hourly", partition_location="p2"))++ table = glue.get_table(DatabaseName=db, Name="events")["Table"]+ assert table["Description"] == "cleaned events"+ assert table["CreateTime"] == created+ assert table["VersionId"] == "2"+ partition = glue.get_partition(DatabaseName=db, TableName="events",+ PartitionValues=["2026-10-01"])["Partition"]+ assert partition["StorageDescriptor"]["Location"] == f"s3://lake-{s}/events/p2/"+ # A property the template dropped is cleared, not left at its old value.+ assert not glue.get_crawler(Name=crawler)["Crawler"].get("Schedule")+ assert glue.get_tags(ResourceArn=_glue_arn(sts, "job", job))["Tags"] == {}+ assert glue.get_trigger(Name=trigger)["Trigger"]["Description"] == "hourly"+ finally:+ _delete_cfn_test_stack(cfn, stack)+++def test_cfn_glue_table_rename_replaces(cfn, glue):+ s = _uuid_mod.uuid4().hex[:8]+ stack = f"glue-ren-{s}"+ template = _glue_data_lake(s)+ _glue_create(cfn, stack, template)+ db = f"lake_{s}"+ try:+ template["Resources"]["Events"]["Properties"]["TableInput"]["Name"] = "events_v2"+ # The partition follows its table through Ref, which replaces it too.+ _glue_update(cfn, stack, template)+ assert _glue_outputs(cfn, stack)["Events"] == "events_v2"+ assert glue.get_table(DatabaseName=db, Name="events_v2")["Table"]["Name"] == "events_v2"+ _glue_not_found(lambda: glue.get_table(DatabaseName=db, Name="events"))+ glue.get_partition(DatabaseName=db, TableName="events_v2", PartitionValues=["2026-10-01"])+ finally:+ _delete_cfn_test_stack(cfn, stack)+++def test_cfn_glue_partition_values_change_replaces(cfn, glue):+ s = _uuid_mod.uuid4().hex[:8]+ stack = f"glue-pv-{s}"+ template = _glue_data_lake(s)+ _glue_create(cfn, stack, template)+ db = f"lake_{s}"+ before = _glue_outputs(cfn, stack)["Day"]+ try:+ template["Resources"]["Day"]["Properties"]["PartitionInput"]["Values"] = ["2026-10-02"]+ _glue_update(cfn, stack, template)+ assert _glue_outputs(cfn, stack)["Day"] != before+ glue.get_partition(DatabaseName=db, TableName="events", PartitionValues=["2026-10-02"])+ _glue_not_found(lambda: glue.get_partition(+ DatabaseName=db, TableName="events", PartitionValues=["2026-10-01"]))+ finally:+ _delete_cfn_test_stack(cfn, stack)+++def test_cfn_glue_database_input_name_change_fails_and_rolls_back(cfn, glue):+ s = _uuid_mod.uuid4().hex[:8]+ stack = f"glue-dbn-{s}"++ def template(name, description):+ return {+ "Resources": {"Db": {"Type": "AWS::Glue::Database", "Properties": {+ "CatalogId": {"Ref": "AWS::AccountId"},+ "DatabaseInput": {"Name": name, "Description": description}}}},+ "Outputs": {"Db": {"Value": {"Ref": "Db"}}},+ }++ _glue_create(cfn, stack, template(f"first_{s}", "one"))+ try:+ cfn.update_stack(StackName=stack, TemplateBody=json.dumps(template(f"second_{s}", "two")))+ assert _wait_stack(cfn, stack)["StackStatus"] == "UPDATE_ROLLBACK_COMPLETE"+ reasons = [e.get("ResourceStatusReason", "")+ for e in cfn.describe_stack_events(StackName=stack)["StackEvents"]+ if e["LogicalResourceId"] == "Db" and e["ResourceStatus"] == "UPDATE_FAILED"]+ assert any(f"Database second_{s} not found" in r for r in reasons), reasons+ assert _glue_outputs(cfn, stack)["Db"] == f"first_{s}"+ assert glue.get_database(Name=f"first_{s}")["Database"]["Description"] == "one"+ _glue_not_found(lambda: glue.get_database(Name=f"second_{s}"))+ finally:+ _delete_cfn_test_stack(cfn, stack)+++def test_cfn_glue_table_moves_database(cfn, glue):+ s = _uuid_mod.uuid4().hex[:8]+ stack = f"glue-mv-{s}"++ def template(db_ref):+ return {"Resources": {+ "A": {"Type": "AWS::Glue::Database", "Properties": {+ "CatalogId": {"Ref": "AWS::AccountId"}, "DatabaseInput": {"Name": f"a_{s}"}}},+ "B": {"Type": "AWS::Glue::Database", "Properties": {+ "CatalogId": {"Ref": "AWS::AccountId"}, "DatabaseInput": {"Name": f"b_{s}"}}},+ "T": {"Type": "AWS::Glue::Table", "Properties": {+ "CatalogId": {"Ref": "AWS::AccountId"}, "DatabaseName": {"Ref": db_ref},+ "TableInput": {"Name": "t"}}},+ }}++ _glue_create(cfn, stack, template("A"))+ try:+ _glue_update(cfn, stack, template("B"))+ glue.get_table(DatabaseName=f"b_{s}", Name="t")+ _glue_not_found(lambda: glue.get_table(DatabaseName=f"a_{s}", Name="t"))+ finally:+ _delete_cfn_test_stack(cfn, stack)+++def test_cfn_glue_named_trigger_type_change_is_refused(cfn, glue):+ s = _uuid_mod.uuid4().hex[:8]+ stack = f"glue-trg-{s}"++ def template(trigger_type):+ props = {"Name": f"trigger-{s}", "Type": trigger_type,+ "Actions": [{"JobName": f"job-{s}"}]}+ if trigger_type == "SCHEDULED":+ props["Schedule"] = "cron(0 3 * * ? *)"+ return {"Resources": {"T": {"Type": "AWS::Glue::Trigger", "Properties": props}}}++ _glue_create(cfn, stack, template("ON_DEMAND"))+ try:+ cfn.update_stack(StackName=stack, TemplateBody=json.dumps(template("SCHEDULED")))+ assert _wait_stack(cfn, stack)["StackStatus"] == "UPDATE_ROLLBACK_COMPLETE"+ events = cfn.describe_stack_events(StackName=stack)["StackEvents"]+ reasons = [e.get("ResourceStatusReason", "") for e in events if e["LogicalResourceId"] == "T"]+ assert any("custom-named resource requires replacing" in r for r in reasons)+ assert glue.get_trigger(Name=f"trigger-{s}")["Trigger"]["Type"] == "ON_DEMAND"+ finally:+ _delete_cfn_test_stack(cfn, stack)+++def test_cfn_glue_generated_names(cfn, glue):+ s = _uuid_mod.uuid4().hex[:8]+ stack = f"Glue-Gen-{s}"+ template = {+ "Resources": {+ "Db": {"Type": "AWS::Glue::Database", "Properties": {+ "CatalogId": {"Ref": "AWS::AccountId"}, "DatabaseInput": {}}},+ "Tbl": {"Type": "AWS::Glue::Table", "Properties": {+ "CatalogId": {"Ref": "AWS::AccountId"}, "DatabaseName": {"Ref": "Db"},+ "TableInput": {"TableType": "EXTERNAL_TABLE"}}},+ "Job": {"Type": "AWS::Glue::Job", "Properties": {+ "Role": _GLUE_ROLE, "Command": {"Name": "pythonshell", "ScriptLocation": "s3://b/k.py"}}},+ },+ "Outputs": {k: {"Value": {"Ref": k}} for k in ("Db", "Tbl", "Job")},+ }+ _glue_create(cfn, stack, template)+ try:+ out = _glue_outputs(cfn, stack)+ # Glue folds catalog names to lowercase, so generated ones start that way.+ assert out["Db"] == out["Db"].lower() and out["Db"].startswith(f"glue-gen-{s}-db-")+ assert out["Tbl"] == out["Tbl"].lower()+ assert out["Job"].startswith(f"{stack}-Job-")+ glue.get_table(DatabaseName=out["Db"], Name=out["Tbl"])+ glue.get_job(JobName=out["Job"])+ # An update under a generated name keeps the same resource.+ template["Resources"]["Job"]["Properties"]["MaxRetries"] = 2+ _glue_update(cfn, stack, template)+ assert _glue_outputs(cfn, stack)["Job"] == out["Job"]+ assert glue.get_job(JobName=out["Job"])["Job"]["MaxRetries"] == 2+ finally:+ _delete_cfn_test_stack(cfn, stack)++[email protected]("rtype,old,new,expected", [+ ("AWS::Glue::Database", {"DatabaseName": "a"}, {"DatabaseName": "b"}, "Always"),+ ("AWS::Glue::Database", {"DatabaseInput": {"Name": "a"}}, {"DatabaseInput": {"Name": "b"}}, "Never"),+ ("AWS::Glue::Job", {"Name": "a"}, {"Name": "b"}, "Always"),+ ("AWS::Glue::Job", {"MaxRetries": 0}, {"MaxRetries": 1}, "Never"),+ ("AWS::Glue::Trigger", {"Type": "ON_DEMAND"}, {"Type": "SCHEDULED"}, "Always"),+ ("AWS::Glue::Crawler", {"Description": "a"}, {"Description": "b"}, "Never"),+ ("AWS::Glue::Partition", {"TableName": "a"}, {"TableName": "b"}, "Conditionally"),+])+def test_cfn_glue_change_set_recreation(rtype, old, new, expected):+ def tmpl(props):+ return {"Resources": {"R": {"Type": rtype, "Properties": props}}}++ change = _diff_resources(tmpl(old), tmpl(new))[0]["ResourceChange"]+ targets = {d["Target"]["Name"]: d["Target"]["RequiresRecreation"]+ for d in change.get("Details", []) if d["Target"].get("Name")}+ assert set(targets.values()) == {expected}+++# ===========================================================================+# AWS::ElastiCache::* resource types+# ===========================================================================++_EC_LAMBDA_ROLE = "arn:aws:iam::000000000000:role/lambda-role"++_ec_requires_docker = pytest.mark.skipif(+ not os.environ.get("DOCKER_NETWORK"),+ reason="DOCKER_NETWORK not set - skipping network connectivity test",+)+++def _ec_create(cfn, name, template):+ cfn.create_stack(StackName=name, TemplateBody=json.dumps(template))+ stack = _wait_stack(cfn, name, timeout=120)+ assert stack["StackStatus"] == "CREATE_COMPLETE", stack.get("StackStatusReason")+++def _ec_update(cfn, name, template):+ cfn.update_stack(StackName=name, TemplateBody=json.dumps(template))+ stack = _wait_stack(cfn, name, timeout=120)+ assert stack["StackStatus"] == "UPDATE_COMPLETE", stack.get("StackStatusReason")+++def _ec_outputs(cfn, name):+ stack = cfn.describe_stacks(StackName=name)["Stacks"][0]+ return {o["OutputKey"]: o["OutputValue"] for o in stack.get("Outputs", [])}+++def _ec_reasons(cfn, name, logical_id):+ events = cfn.describe_stack_events(StackName=name)["StackEvents"]+ return [e.get("ResourceStatusReason", "") for e in events+ if e["LogicalResourceId"] == logical_id]+++def _ec_error_code(call):+ with pytest.raises(ClientError) as exc:+ call()+ return exc.value.response["Error"]["Code"]+++def _ec_params(ec, group):+ return {p["ParameterName"]: p["ParameterValue"]+ for p in ec.describe_cache_parameters(CacheParameterGroupName=group)["Parameters"]}+++def _ec_cache_stack(s, *, rg_description="sessions", num_cache_clusters=2,+ params=None, subnet_description="cache subnets",+ access_string="on ~app:* +@all", extra_user=False,+ cluster_nodes=1, rg_tags=None):+ resources = {+ "Subnets": {"Type": "AWS::ElastiCache::SubnetGroup", "Properties": {+ "CacheSubnetGroupName": f"subnets-{s}",+ "Description": subnet_description,+ "SubnetIds": ["subnet-aaa", "subnet-bbb"],+ }},+ "Params": {"Type": "AWS::ElastiCache::ParameterGroup", "Properties": {+ "CacheParameterGroupFamily": "redis7",+ "Description": "app params",+ "Properties": params if params is not None else {+ "maxmemory-policy": "allkeys-lru", "timeout": "300"},+ }},+ "User": {"Type": "AWS::ElastiCache::User", "Properties": {+ "UserId": f"app-{s}", "UserName": f"app-{s}", "Engine": "redis",+ "AccessString": access_string, "Passwords": ["correct-horse-battery"],+ }},+ "Users": {"Type": "AWS::ElastiCache::UserGroup", "Properties": {+ "UserGroupId": f"users-{s}", "Engine": "redis",+ "UserIds": [{"Ref": "User"}] + ([{"Ref": "Other"}] if extra_user else []),+ }},+ "Cache": {"Type": "AWS::ElastiCache::ReplicationGroup", "Properties": {+ "ReplicationGroupId": f"cache-{s}",+ "ReplicationGroupDescription": rg_description,+ "Engine": "redis",+ "CacheNodeType": "cache.t3.micro",+ "NumCacheClusters": num_cache_clusters,+ "CacheSubnetGroupName": {"Ref": "Subnets"},+ "CacheParameterGroupName": {"Ref": "Params"},+ "UserGroupIds": [{"Ref": "Users"}],+ "TransitEncryptionEnabled": True,+ "Tags": rg_tags if rg_tags is not None else [{"Key": "team", "Value": "data"}],+ }},+ "Single": {"Type": "AWS::ElastiCache::CacheCluster", "Properties": {+ "ClusterName": f"single-{s}",+ "Engine": "redis",+ "CacheNodeType": "cache.t3.micro",+ "NumCacheNodes": cluster_nodes,+ "PreferredAvailabilityZone": "us-east-1a",+ "CacheSubnetGroupName": {"Ref": "Subnets"},+ }},+ }+ if extra_user:+ resources["Other"] = {"Type": "AWS::ElastiCache::User", "Properties": {+ "UserId": f"other-{s}", "UserName": f"other-{s}", "Engine": "redis",+ "AccessString": "on ~* +@read", "NoPasswordRequired": True,+ }}+ outputs = {k: {"Value": {"Ref": k}} for k in resources}++ def att(logical_id, attr):+ return {"Value": {"Fn::GetAtt": [logical_id, attr]}}++ outputs.update({+ "ParamsName": att("Params", "CacheParameterGroupName"),+ "UserArn": att("User", "Arn"),+ "UsersArn": att("Users", "Arn"),+ "PrimaryAddress": att("Cache", "PrimaryEndPoint.Address"),+ "PrimaryPort": att("Cache", "PrimaryEndPoint.Port"),+ "ReaderAddress": att("Cache", "ReaderEndPoint.Address"),+ "ReadAddresses": att("Cache", "ReadEndPoint.Addresses"),+ "SingleAddress": att("Single", "RedisEndpoint.Address"),+ "SinglePort": att("Single", "RedisEndpoint.Port"),+ })+ return {"Resources": resources, "Outputs": outputs}+++def test_cfn_elasticache_stack_create_and_delete(cfn, ec):+ s = _uuid_mod.uuid4().hex[:8]+ stack = f"ec-full-{s}"+ _ec_create(cfn, stack, _ec_cache_stack(s))+ out = _ec_outputs(cfn, stack)+ assert out["Subnets"] == f"subnets-{s}"+ assert out["Cache"] == f"cache-{s}"+ assert out["Single"] == f"single-{s}"+ assert out["User"] == f"app-{s}" and out["Users"] == f"users-{s}"+ # The parameter group's name is read-only in the schema: always generated.+ assert out["Params"] == out["ParamsName"] == out["Params"].lower()+ try:+ groups = ec.describe_cache_subnet_groups(CacheSubnetGroupName=f"subnets-{s}")+ subnets = groups["CacheSubnetGroups"][0]["Subnets"]+ assert [n["SubnetIdentifier"] for n in subnets] == ["subnet-aaa", "subnet-bbb"]+ assert _ec_params(ec, out["Params"])["maxmemory-policy"] == "allkeys-lru"++ user = ec.describe_users(UserId=f"app-{s}")["Users"][0]+ assert user["ARN"] == out["UserArn"]+ assert user["AccessString"] == "on ~app:* +@all"+ group = ec.describe_user_groups(UserGroupId=f"users-{s}")["UserGroups"][0]+ assert group["ARN"] == out["UsersArn"]+ assert group["UserIds"] == [f"app-{s}"]+ assert group["ReplicationGroups"] == [f"cache-{s}"]++ # The stack's endpoints are the ones the API reports for the same group.+ rg = ec.describe_replication_groups(ReplicationGroupId=f"cache-{s}")["ReplicationGroups"][0]+ primary = rg["NodeGroups"][0]["PrimaryEndpoint"]+ assert (out["PrimaryAddress"], out["PrimaryPort"]) == (primary["Address"], str(primary["Port"]))+ assert out["ReaderAddress"] == rg["NodeGroups"][0]["ReaderEndpoint"]["Address"]+ replicas = [m for m in rg["NodeGroups"][0]["NodeGroupMembers"] if m["CurrentRole"] == "replica"]+ assert out["ReadAddresses"] == ",".join(m["ReadEndpoint"]["Address"] for m in replicas)+ assert rg["CacheNodeType"] == "cache.t3.micro"+ assert rg["TransitEncryptionEnabled"] is True+ tags = ec.list_tags_for_resource(ResourceName=rg["ARN"])["TagList"]+ assert {"Key": "team", "Value": "data"} in tags++ cluster = ec.describe_cache_clusters(+ CacheClusterId=f"single-{s}", ShowCacheNodeInfo=True)["CacheClusters"][0]+ node = cluster["CacheNodes"][0]["Endpoint"]+ assert (out["SingleAddress"], out["SinglePort"]) == (node["Address"], str(node["Port"]))+ assert cluster["CacheSubnetGroupName"] == f"subnets-{s}"+ finally:+ _delete_cfn_test_stack(cfn, stack)++ assert _ec_error_code(lambda: ec.describe_replication_groups(+ ReplicationGroupId=f"cache-{s}")) == "ReplicationGroupNotFoundFault"+ assert _ec_error_code(lambda: ec.describe_cache_clusters(+ CacheClusterId=f"single-{s}")) == "CacheClusterNotFound"+ assert _ec_error_code(lambda: ec.describe_cache_subnet_groups(+ CacheSubnetGroupName=f"subnets-{s}")) == "CacheSubnetGroupNotFoundFault"+ assert _ec_error_code(lambda: ec.describe_cache_parameter_groups(+ CacheParameterGroupName=out["Params"])) == "CacheParameterGroupNotFound"+ assert _ec_error_code(lambda: ec.describe_users(UserId=f"app-{s}")) == "UserNotFound"+ assert _ec_error_code(lambda: ec.describe_user_groups(+ UserGroupId=f"users-{s}")) == "UserGroupNotFound"+++def test_cfn_elasticache_update_in_place(cfn, ec):+ s = _uuid_mod.uuid4().hex[:8]+ stack = f"ec-upd-{s}"+ _ec_create(cfn, stack, _ec_cache_stack(s))+ before = _ec_outputs(cfn, stack)+ try:+ _ec_update(cfn, stack, _ec_cache_stack(+ s, rg_description="sessions v2", num_cache_clusters=3,+ params={"maxmemory-policy": "volatile-ttl"}, subnet_description="new subnets",+ access_string="on ~* +@all", extra_user=True, cluster_nodes=2,+ rg_tags=[{"Key": "team", "Value": "platform"}]))+ after = _ec_outputs(cfn, stack)+ for key in ("Subnets", "Params", "User", "Users", "Cache", "Single"):+ assert after[key] == before[key], key++ rg = ec.describe_replication_groups(ReplicationGroupId=f"cache-{s}")["ReplicationGroups"][0]+ assert rg["Description"] == "sessions v2"+ assert len(rg["NodeGroups"][0]["NodeGroupMembers"]) == 3+ tags = ec.list_tags_for_resource(ResourceName=rg["ARN"])["TagList"]+ assert {"Key": "team", "Value": "platform"} in tags++ params = _ec_params(ec, before["Params"])+ assert params["maxmemory-policy"] == "volatile-ttl"+ # A parameter the template dropped goes back to its default.+ assert params["timeout"] == "0"+ group = ec.describe_cache_subnet_groups(CacheSubnetGroupName=f"subnets-{s}")+ assert group["CacheSubnetGroups"][0]["CacheSubnetGroupDescription"] == "new subnets"+ assert ec.describe_users(UserId=f"app-{s}")["Users"][0]["AccessString"] == "on ~* +@all"+ users = ec.describe_user_groups(UserGroupId=f"users-{s}")["UserGroups"][0]["UserIds"]+ assert sorted(users) == sorted([f"app-{s}", f"other-{s}"])+ cluster = ec.describe_cache_clusters(CacheClusterId=f"single-{s}")["CacheClusters"][0]+ assert cluster["NumCacheNodes"] == 2+ finally:+ _delete_cfn_test_stack(cfn, stack)+++def test_cfn_elasticache_replication_group_rename_replaces(cfn, ec):+ s = _uuid_mod.uuid4().hex[:8]+ stack = f"ec-ren-{s}"++ def template(rg_id):+ return {"Resources": {"Rg": {"Type": "AWS::ElastiCache::ReplicationGroup", "Properties": {+ "ReplicationGroupId": rg_id, "ReplicationGroupDescription": "rename",+ "Engine": "redis", "CacheNodeType": "cache.t3.micro"}}}}++ _ec_create(cfn, stack, template(f"first-{s}"))+ try:+ _ec_update(cfn, stack, template(f"second-{s}"))+ ec.describe_replication_groups(ReplicationGroupId=f"second-{s}")+ assert _ec_error_code(lambda: ec.describe_replication_groups(+ ReplicationGroupId=f"first-{s}")) == "ReplicationGroupNotFoundFault"+ finally:+ _delete_cfn_test_stack(cfn, stack)+++def test_cfn_elasticache_generated_cluster_replaced_on_create_only_change(cfn, ec):+ s = _uuid_mod.uuid4().hex[:8]+ stack = f"Ec-Gen-{s}"++ def template(subnet_ref):+ return {+ "Resources": {+ "A": {"Type": "AWS::ElastiCache::SubnetGroup", "Properties": {+ "Description": "a", "SubnetIds": ["subnet-a"]}},+ "B": {"Type": "AWS::ElastiCache::SubnetGroup", "Properties": {+ "Description": "b", "SubnetIds": ["subnet-b"]}},+ "C": {"Type": "AWS::ElastiCache::CacheCluster", "Properties": {+ "Engine": "redis", "CacheNodeType": "cache.t3.micro", "NumCacheNodes": 1,+ "CacheSubnetGroupName": {"Ref": subnet_ref}}},+ },+ "Outputs": {k: {"Value": {"Ref": k}} for k in ("A", "B", "C")},+ }++ _ec_create(cfn, stack, template("A"))+ try:+ out = _ec_outputs(cfn, stack)+ # Generated names are lowercase, as ElastiCache stores them, and a+ # cluster name fits the 50-character limit.+ assert out["A"] == out["A"].lower() and out["A"].startswith(f"ec-gen-{s}-a-")+ assert out["C"] == out["C"].lower() and len(out["C"]) <= 50+ first = ec.describe_cache_clusters(CacheClusterId=out["C"])["CacheClusters"][0]+ # CacheSubnetGroupName is create-only: the cluster is replaced and+ # takes its generated name back.+ _ec_update(cfn, stack, template("B"))+ assert _ec_outputs(cfn, stack)["C"] == out["C"]+ second = ec.describe_cache_clusters(CacheClusterId=out["C"])["CacheClusters"][0]+ assert second["CacheSubnetGroupName"] == out["B"]+ assert second["CacheClusterCreateTime"] >= first["CacheClusterCreateTime"]+ finally:+ _delete_cfn_test_stack(cfn, stack)+++def test_cfn_elasticache_named_cluster_engine_change_is_refused(cfn, ec):+ s = _uuid_mod.uuid4().hex[:8]+ stack = f"ec-ref-{s}"++ def template(engine):+ return {"Resources": {"C": {"Type": "AWS::ElastiCache::CacheCluster", "Properties": {+ "ClusterName": f"named-{s}", "Engine": engine,+ "CacheNodeType": "cache.t3.micro", "NumCacheNodes": 1}}}}++ _ec_create(cfn, stack, template("redis"))+ try:+ cfn.update_stack(StackName=stack, TemplateBody=json.dumps(template("memcached")))+ assert _wait_stack(cfn, stack, timeout=120)["StackStatus"] == "UPDATE_ROLLBACK_COMPLETE"+ assert any("custom-named resource requires replacing" in r+ for r in _ec_reasons(cfn, stack, "C"))+ cluster = ec.describe_cache_clusters(CacheClusterId=f"named-{s}")["CacheClusters"][0]+ assert cluster["Engine"] == "redis"+ finally:+ _delete_cfn_test_stack(cfn, stack)+++def test_cfn_elasticache_configuration_endpoint_needs_cluster_mode(cfn):+ # "Fn::GetAtt returns a value for this attribute only if the replication+ # group is clustered. Otherwise, Fn::GetAtt fails."+ s = _uuid_mod.uuid4().hex[:8]+ stack = f"ec-cfg-{s}"+ cfn.create_stack(StackName=stack, TemplateBody=json.dumps({+ "Resources": {"Rg": {"Type": "AWS::ElastiCache::ReplicationGroup", "Properties": {+ "ReplicationGroupDescription": "no cluster mode", "Engine": "redis",+ "CacheNodeType": "cache.t3.micro"}}},+ "Outputs": {"Cfg": {"Value": {"Fn::GetAtt": ["Rg", "ConfigurationEndPoint.Address"]}}},+ }))+ try:+ assert _wait_stack(cfn, stack, timeout=120)["StackStatus"] == "ROLLBACK_COMPLETE"+ finally:+ _delete_cfn_test_stack(cfn, stack)+++def test_cfn_elasticache_memcached_configuration_endpoint(cfn, ec):+ s = _uuid_mod.uuid4().hex[:8]+ stack = f"ec-mc-{s}"+ _ec_create(cfn, stack, {+ "Resources": {"Mc": {"Type": "AWS::ElastiCache::CacheCluster", "Properties": {+ "ClusterName": f"mc-{s}", "Engine": "memcached", "EngineVersion": "1.6.17",+ "CacheNodeType": "cache.t3.micro", "NumCacheNodes": 1}}},+ "Outputs": {"Address": {"Value": {"Fn::GetAtt": ["Mc", "ConfigurationEndpoint.Address"]}},+ "Port": {"Value": {"Fn::GetAtt": ["Mc", "ConfigurationEndpoint.Port"]}}},+ })+ try:+ out = _ec_outputs(cfn, stack)+ node = ec.describe_cache_clusters(+ CacheClusterId=f"mc-{s}", ShowCacheNodeInfo=True)["CacheClusters"][0]["CacheNodes"][0]+ assert (out["Address"], out["Port"]) == (node["Endpoint"]["Address"], str(node["Endpoint"]["Port"]))+ finally:+ _delete_cfn_test_stack(cfn, stack)++[email protected]("rtype,old,new,expected", [+ ("AWS::ElastiCache::CacheCluster", {"Engine": "redis"}, {"Engine": "memcached"}, "Always"),+ ("AWS::ElastiCache::CacheCluster", {"NumCacheNodes": 1}, {"NumCacheNodes": 2}, "Conditionally"),+ ("AWS::ElastiCache::CacheCluster", {"IpDiscovery": "ipv4"}, {"IpDiscovery": "ipv6"}, "Never"),+ ("AWS::ElastiCache::ReplicationGroup", {"Port": 6379}, {"Port": 6380}, "Always"),+ ("AWS::ElastiCache::ReplicationGroup", {"AuthToken": "a" * 16}, {"AuthToken": "b" * 16}, "Conditionally"),+ ("AWS::ElastiCache::ReplicationGroup", {"CacheNodeType": "cache.t3.micro"},+ {"CacheNodeType": "cache.t3.small"}, "Never"),+ ("AWS::ElastiCache::ParameterGroup", {"CacheParameterGroupFamily": "redis6.x"},+ {"CacheParameterGroupFamily": "redis7"}, "Always"),+ ("AWS::ElastiCache::User", {"UserName": "a"}, {"UserName": "b"}, "Always"),+ ("AWS::ElastiCache::UserGroup", {"UserIds": ["a"]}, {"UserIds": ["b"]}, "Never"),+])+def test_cfn_elasticache_change_set_recreation(rtype, old, new, expected):+ def tmpl(props):+ return {"Resources": {"R": {"Type": rtype, "Properties": props}}}++ change = _diff_resources(tmpl(old), tmpl(new))[0]["ResourceChange"]+ targets = {d["Target"]["Name"]: d["Target"]["RequiresRecreation"]+ for d in change.get("Details", []) if d["Target"].get("Name")}+ assert set(targets.values()) == {expected}+++@_ec_requires_docker[email protected]_plane+def test_cfn_elasticache_lambda_reaches_replication_group(cfn, lam):+ """The issue's use case: a stack passes PrimaryEndPoint into a function's+ environment, and the function talks to the container behind it."""+ s = _uuid_mod.uuid4().hex[:8]+ stack = f"ec-lam-{s}"+ code = (+ "import os, socket\n"+ "def handler(event, context):\n"+ " s = socket.create_connection((os.environ['REDIS_HOST'], int(os.environ['REDIS_PORT'])), timeout=5)\n"+ " s.sendall(b'PING\\r\\n')\n"+ " reply = s.recv(64).decode()\n"+ " s.close()\n"+ " return {'reply': reply.strip()}\n"+ )+ _ec_create(cfn, stack, {+ "Resources": {+ "Cache": {"Type": "AWS::ElastiCache::ReplicationGroup", "Properties": {+ "ReplicationGroupDescription": "lambda", "Engine": "redis",+ "CacheNodeType": "cache.t3.micro"}},+ "Fn": {"Type": "AWS::Lambda::Function", "Properties": {+ "FunctionName": f"ec-ping-{s}", "Runtime": "python3.12",+ "Handler": "index.handler", "Role": _EC_LAMBDA_ROLE, "Timeout": 15,+ "Code": {"ZipFile": code},+ "Environment": {"Variables": {+ "REDIS_HOST": {"Fn::GetAtt": ["Cache", "PrimaryEndPoint.Address"]},+ "REDIS_PORT": {"Fn::GetAtt": ["Cache", "PrimaryEndPoint.Port"]},+ }}}},+ },+ })+ try:+ import time+ deadline = time.time() + 60+ while True:+ resp = lam.invoke(FunctionName=f"ec-ping-{s}", Payload=b"{}")+ result = json.loads(resp["Payload"].read())+ if result.get("reply") == "+PONG" or time.time() > deadline:+ break+ time.sleep(1)+ assert result.get("reply") == "+PONG", result+ finally:+ _delete_cfn_test_stack(cfn, stack)diff --git a/tests/test_cfn_elasticache.py b/tests/test_cfn_elasticache.pydeleted file mode 100644index 31ee80d3..00000000--- a/tests/test_cfn_elasticache.py+++ /dev/null@@ -1,409 +0,0 @@-"""CloudFormation AWS::ElastiCache::* resource types (#1874)."""--import json-import os-import uuid--import pytest-from botocore.exceptions import ClientError, WaiterError--from ministack.services.cloudformation.stacks import _diff_resources--_WAIT = {"Delay": 1, "MaxAttempts": 120}-_LAMBDA_ROLE = "arn:aws:iam::000000000000:role/lambda-role"--requires_docker = pytest.mark.skipif(- not os.environ.get("DOCKER_NETWORK"),- reason="DOCKER_NETWORK not set - skipping network connectivity test",-)---def _suffix():- return uuid.uuid4().hex[:8]---def _create(cfn, name, template):- cfn.create_stack(StackName=name, TemplateBody=json.dumps(template))- cfn.get_waiter("stack_create_complete").wait(StackName=name, WaiterConfig=_WAIT)---def _update(cfn, name, template):- cfn.update_stack(StackName=name, TemplateBody=json.dumps(template))- cfn.get_waiter("stack_update_complete").wait(StackName=name, WaiterConfig=_WAIT)---def _delete(cfn, name):- cfn.delete_stack(StackName=name)- cfn.get_waiter("stack_delete_complete").wait(StackName=name, WaiterConfig=_WAIT)---def _outputs(cfn, name):- stack = cfn.describe_stacks(StackName=name)["Stacks"][0]- return {o["OutputKey"]: o["OutputValue"] for o in stack.get("Outputs", [])}---def _reasons(cfn, name, logical_id):- events = cfn.describe_stack_events(StackName=name)["StackEvents"]- return [e.get("ResourceStatusReason", "") for e in events- if e["LogicalResourceId"] == logical_id]---def _error_code(call):- with pytest.raises(ClientError) as exc:- call()- return exc.value.response["Error"]["Code"]---def _params(ec, group):- return {p["ParameterName"]: p["ParameterValue"]- for p in ec.describe_cache_parameters(CacheParameterGroupName=group)["Parameters"]}---def _cache_stack(s, *, rg_description="sessions", num_cache_clusters=2,- params=None, subnet_description="cache subnets",- access_string="on ~app:* +@all", extra_user=False,- cluster_nodes=1, rg_tags=None):- resources = {- "Subnets": {"Type": "AWS::ElastiCache::SubnetGroup", "Properties": {- "CacheSubnetGroupName": f"subnets-{s}",- "Description": subnet_description,- "SubnetIds": ["subnet-aaa", "subnet-bbb"],- }},- "Params": {"Type": "AWS::ElastiCache::ParameterGroup", "Properties": {- "CacheParameterGroupFamily": "redis7",- "Description": "app params",- "Properties": params if params is not None else {- "maxmemory-policy": "allkeys-lru", "timeout": "300"},- }},- "User": {"Type": "AWS::ElastiCache::User", "Properties": {- "UserId": f"app-{s}", "UserName": f"app-{s}", "Engine": "redis",- "AccessString": access_string, "Passwords": ["correct-horse-battery"],- }},- "Users": {"Type": "AWS::ElastiCache::UserGroup", "Properties": {- "UserGroupId": f"users-{s}", "Engine": "redis",- "UserIds": [{"Ref": "User"}] + ([{"Ref": "Other"}] if extra_user else []),- }},- "Cache": {"Type": "AWS::ElastiCache::ReplicationGroup", "Properties": {- "ReplicationGroupId": f"cache-{s}",- "ReplicationGroupDescription": rg_description,- "Engine": "redis",- "CacheNodeType": "cache.t3.micro",- "NumCacheClusters": num_cache_clusters,- "CacheSubnetGroupName": {"Ref": "Subnets"},- "CacheParameterGroupName": {"Ref": "Params"},- "UserGroupIds": [{"Ref": "Users"}],- "TransitEncryptionEnabled": True,- "Tags": rg_tags if rg_tags is not None else [{"Key": "team", "Value": "data"}],- }},- "Single": {"Type": "AWS::ElastiCache::CacheCluster", "Properties": {- "ClusterName": f"single-{s}",- "Engine": "redis",- "CacheNodeType": "cache.t3.micro",- "NumCacheNodes": cluster_nodes,- "CacheSubnetGroupName": {"Ref": "Subnets"},- }},- }- if extra_user:- resources["Other"] = {"Type": "AWS::ElastiCache::User", "Properties": {- "UserId": f"other-{s}", "UserName": f"other-{s}", "Engine": "redis",- "AccessString": "on ~* +@read", "NoPasswordRequired": True,- }}- outputs = {k: {"Value": {"Ref": k}} for k in resources}-- def att(logical_id, attr):- return {"Value": {"Fn::GetAtt": [logical_id, attr]}}-- outputs.update({- "ParamsName": att("Params", "CacheParameterGroupName"),- "UserArn": att("User", "Arn"),- "UsersArn": att("Users", "Arn"),- "PrimaryAddress": att("Cache", "PrimaryEndPoint.Address"),- "PrimaryPort": att("Cache", "PrimaryEndPoint.Port"),- "ReaderAddress": att("Cache", "ReaderEndPoint.Address"),- "ReadAddresses": att("Cache", "ReadEndPoint.Addresses"),- "SingleAddress": att("Single", "RedisEndpoint.Address"),- "SinglePort": att("Single", "RedisEndpoint.Port"),- })- return {"Resources": resources, "Outputs": outputs}---def test_cfn_elasticache_stack_create_and_delete(cfn, ec):- s = _suffix()- stack = f"ec-full-{s}"- _create(cfn, stack, _cache_stack(s))- out = _outputs(cfn, stack)- assert out["Subnets"] == f"subnets-{s}"- assert out["Cache"] == f"cache-{s}"- assert out["Single"] == f"single-{s}"- assert out["User"] == f"app-{s}" and out["Users"] == f"users-{s}"- # The parameter group's name is read-only in the schema: always generated.- assert out["Params"] == out["ParamsName"] == out["Params"].lower()- try:- groups = ec.describe_cache_subnet_groups(CacheSubnetGroupName=f"subnets-{s}")- subnets = groups["CacheSubnetGroups"][0]["Subnets"]- assert [n["SubnetIdentifier"] for n in subnets] == ["subnet-aaa", "subnet-bbb"]- assert _params(ec, out["Params"])["maxmemory-policy"] == "allkeys-lru"-- user = ec.describe_users(UserId=f"app-{s}")["Users"][0]- assert user["ARN"] == out["UserArn"]- assert user["AccessString"] == "on ~app:* +@all"- group = ec.describe_user_groups(UserGroupId=f"users-{s}")["UserGroups"][0]- assert group["ARN"] == out["UsersArn"]- assert group["UserIds"] == [f"app-{s}"]- assert group["ReplicationGroups"] == [f"cache-{s}"]-- # The stack's endpoints are the ones the API reports for the same group.- rg = ec.describe_replication_groups(ReplicationGroupId=f"cache-{s}")["ReplicationGroups"][0]- primary = rg["NodeGroups"][0]["PrimaryEndpoint"]- assert (out["PrimaryAddress"], out["PrimaryPort"]) == (primary["Address"], str(primary["Port"]))- assert out["ReaderAddress"] == rg["NodeGroups"][0]["ReaderEndpoint"]["Address"]- replicas = [m for m in rg["NodeGroups"][0]["NodeGroupMembers"] if m["CurrentRole"] == "replica"]- assert out["ReadAddresses"] == ",".join(m["ReadEndpoint"]["Address"] for m in replicas)- assert rg["CacheNodeType"] == "cache.t3.micro"- assert rg["TransitEncryptionEnabled"] is True- tags = ec.list_tags_for_resource(ResourceName=rg["ARN"])["TagList"]- assert {"Key": "team", "Value": "data"} in tags-- cluster = ec.describe_cache_clusters(- CacheClusterId=f"single-{s}", ShowCacheNodeInfo=True)["CacheClusters"][0]- node = cluster["CacheNodes"][0]["Endpoint"]- assert (out["SingleAddress"], out["SinglePort"]) == (node["Address"], str(node["Port"]))- assert cluster["CacheSubnetGroupName"] == f"subnets-{s}"- finally:- _delete(cfn, stack)-- assert _error_code(lambda: ec.describe_replication_groups(- ReplicationGroupId=f"cache-{s}")) == "ReplicationGroupNotFoundFault"- assert _error_code(lambda: ec.describe_cache_clusters(- CacheClusterId=f"single-{s}")) == "CacheClusterNotFound"- assert _error_code(lambda: ec.describe_cache_subnet_groups(- CacheSubnetGroupName=f"subnets-{s}")) == "CacheSubnetGroupNotFoundFault"- assert _error_code(lambda: ec.describe_cache_parameter_groups(- CacheParameterGroupName=out["Params"])) == "CacheParameterGroupNotFound"- assert _error_code(lambda: ec.describe_users(UserId=f"app-{s}")) == "UserNotFound"- assert _error_code(lambda: ec.describe_user_groups(- UserGroupId=f"users-{s}")) == "UserGroupNotFound"---def test_cfn_elasticache_update_in_place(cfn, ec):- s = _suffix()- stack = f"ec-upd-{s}"- _create(cfn, stack, _cache_stack(s))- before = _outputs(cfn, stack)- try:- _update(cfn, stack, _cache_stack(- s, rg_description="sessions v2", num_cache_clusters=3,- params={"maxmemory-policy": "volatile-ttl"}, subnet_description="new subnets",- access_string="on ~* +@all", extra_user=True, cluster_nodes=2,- rg_tags=[{"Key": "team", "Value": "platform"}]))- after = _outputs(cfn, stack)- for key in ("Subnets", "Params", "User", "Users", "Cache", "Single"):- assert after[key] == before[key], key-- rg = ec.describe_replication_groups(ReplicationGroupId=f"cache-{s}")["ReplicationGroups"][0]- assert rg["Description"] == "sessions v2"- assert len(rg["NodeGroups"][0]["NodeGroupMembers"]) == 3- tags = ec.list_tags_for_resource(ResourceName=rg["ARN"])["TagList"]- assert {"Key": "team", "Value": "platform"} in tags-- params = _params(ec, before["Params"])- assert params["maxmemory-policy"] == "volatile-ttl"- # A parameter the template dropped goes back to its default.- assert params["timeout"] == "0"- group = ec.describe_cache_subnet_groups(CacheSubnetGroupName=f"subnets-{s}")- assert group["CacheSubnetGroups"][0]["CacheSubnetGroupDescription"] == "new subnets"- assert ec.describe_users(UserId=f"app-{s}")["Users"][0]["AccessString"] == "on ~* +@all"- users = ec.describe_user_groups(UserGroupId=f"users-{s}")["UserGroups"][0]["UserIds"]- assert sorted(users) == sorted([f"app-{s}", f"other-{s}"])- cluster = ec.describe_cache_clusters(CacheClusterId=f"single-{s}")["CacheClusters"][0]- assert cluster["NumCacheNodes"] == 2- finally:- _delete(cfn, stack)---def test_cfn_elasticache_replication_group_rename_replaces(cfn, ec):- s = _suffix()- stack = f"ec-ren-{s}"-- def template(rg_id):- return {"Resources": {"Rg": {"Type": "AWS::ElastiCache::ReplicationGroup", "Properties": {- "ReplicationGroupId": rg_id, "ReplicationGroupDescription": "rename",- "Engine": "redis", "CacheNodeType": "cache.t3.micro"}}}}-- _create(cfn, stack, template(f"first-{s}"))- try:- _update(cfn, stack, template(f"second-{s}"))- ec.describe_replication_groups(ReplicationGroupId=f"second-{s}")- assert _error_code(lambda: ec.describe_replication_groups(- ReplicationGroupId=f"first-{s}")) == "ReplicationGroupNotFoundFault"- finally:- _delete(cfn, stack)---def test_cfn_elasticache_generated_cluster_replaced_on_create_only_change(cfn, ec):- s = _suffix()- stack = f"Ec-Gen-{s}"-- def template(subnet_ref):- return {- "Resources": {- "A": {"Type": "AWS::ElastiCache::SubnetGroup", "Properties": {- "Description": "a", "SubnetIds": ["subnet-a"]}},- "B": {"Type": "AWS::ElastiCache::SubnetGroup", "Properties": {- "Description": "b", "SubnetIds": ["subnet-b"]}},- "C": {"Type": "AWS::ElastiCache::CacheCluster", "Properties": {- "Engine": "redis", "CacheNodeType": "cache.t3.micro", "NumCacheNodes": 1,- "CacheSubnetGroupName": {"Ref": subnet_ref}}},- },- "Outputs": {k: {"Value": {"Ref": k}} for k in ("A", "B", "C")},- }-- _create(cfn, stack, template("A"))- try:- out = _outputs(cfn, stack)- # Generated names are lowercase, as ElastiCache stores them, and a- # cluster name fits the 50-character limit.- assert out["A"] == out["A"].lower() and out["A"].startswith(f"ec-gen-{s}-a-")- assert out["C"] == out["C"].lower() and len(out["C"]) <= 50- first = ec.describe_cache_clusters(CacheClusterId=out["C"])["CacheClusters"][0]- # CacheSubnetGroupName is create-only: the cluster is replaced and- # takes its generated name back.- _update(cfn, stack, template("B"))- assert _outputs(cfn, stack)["C"] == out["C"]- second = ec.describe_cache_clusters(CacheClusterId=out["C"])["CacheClusters"][0]- assert second["CacheSubnetGroupName"] == out["B"]- assert second["CacheClusterCreateTime"] >= first["CacheClusterCreateTime"]- finally:- _delete(cfn, stack)---def test_cfn_elasticache_named_cluster_engine_change_is_refused(cfn, ec):- s = _suffix()- stack = f"ec-ref-{s}"-- def template(engine):- return {"Resources": {"C": {"Type": "AWS::ElastiCache::CacheCluster", "Properties": {- "ClusterName": f"named-{s}", "Engine": engine,- "CacheNodeType": "cache.t3.micro", "NumCacheNodes": 1}}}}-- _create(cfn, stack, template("redis"))- try:- cfn.update_stack(StackName=stack, TemplateBody=json.dumps(template("memcached")))- with pytest.raises(WaiterError):- cfn.get_waiter("stack_update_complete").wait(StackName=stack, WaiterConfig=_WAIT)- assert any("custom-named resource requires replacing" in r- for r in _reasons(cfn, stack, "C"))- cluster = ec.describe_cache_clusters(CacheClusterId=f"named-{s}")["CacheClusters"][0]- assert cluster["Engine"] == "redis"- finally:- _delete(cfn, stack)---def test_cfn_elasticache_configuration_endpoint_needs_cluster_mode(cfn):- # "Fn::GetAtt returns a value for this attribute only if the replication- # group is clustered. Otherwise, Fn::GetAtt fails."- s = _suffix()- stack = f"ec-cfg-{s}"- cfn.create_stack(StackName=stack, TemplateBody=json.dumps({- "Resources": {"Rg": {"Type": "AWS::ElastiCache::ReplicationGroup", "Properties": {- "ReplicationGroupDescription": "no cluster mode", "Engine": "redis",- "CacheNodeType": "cache.t3.micro"}}},- "Outputs": {"Cfg": {"Value": {"Fn::GetAtt": ["Rg", "ConfigurationEndPoint.Address"]}}},- }))- try:- with pytest.raises(WaiterError):- cfn.get_waiter("stack_create_complete").wait(StackName=stack, WaiterConfig=_WAIT)- status = cfn.describe_stacks(StackName=stack)["Stacks"][0]["StackStatus"]- assert status == "ROLLBACK_COMPLETE"- finally:- _delete(cfn, stack)---def test_cfn_elasticache_memcached_configuration_endpoint(cfn, ec):- s = _suffix()- stack = f"ec-mc-{s}"- _create(cfn, stack, {- "Resources": {"Mc": {"Type": "AWS::ElastiCache::CacheCluster", "Properties": {- "ClusterName": f"mc-{s}", "Engine": "memcached", "EngineVersion": "1.6.17",- "CacheNodeType": "cache.t3.micro", "NumCacheNodes": 1}}},- "Outputs": {"Address": {"Value": {"Fn::GetAtt": ["Mc", "ConfigurationEndpoint.Address"]}},- "Port": {"Value": {"Fn::GetAtt": ["Mc", "ConfigurationEndpoint.Port"]}}},- })- try:- out = _outputs(cfn, stack)- node = ec.describe_cache_clusters(- CacheClusterId=f"mc-{s}", ShowCacheNodeInfo=True)["CacheClusters"][0]["CacheNodes"][0]- assert (out["Address"], out["Port"]) == (node["Endpoint"]["Address"], str(node["Endpoint"]["Port"]))- finally:- _delete(cfn, stack)---# Expected values follow the createOnlyProperties and-# conditionalCreateOnlyProperties of the published registry schemas; they were-# not observed on an AWS change set.[email protected]("rtype,old,new,expected", [- ("AWS::ElastiCache::CacheCluster", {"Engine": "redis"}, {"Engine": "memcached"}, "Always"),- ("AWS::ElastiCache::CacheCluster", {"NumCacheNodes": 1}, {"NumCacheNodes": 2}, "Never"),- ("AWS::ElastiCache::CacheCluster", {"IpDiscovery": "ipv4"}, {"IpDiscovery": "ipv6"}, "Conditionally"),- ("AWS::ElastiCache::ReplicationGroup", {"Port": 6379}, {"Port": 6380}, "Always"),- ("AWS::ElastiCache::ReplicationGroup", {"AuthToken": "a" * 16}, {"AuthToken": "b" * 16}, "Conditionally"),- ("AWS::ElastiCache::ReplicationGroup", {"CacheNodeType": "cache.t3.micro"},- {"CacheNodeType": "cache.t3.small"}, "Never"),- ("AWS::ElastiCache::ParameterGroup", {"CacheParameterGroupFamily": "redis6.x"},- {"CacheParameterGroupFamily": "redis7"}, "Always"),- ("AWS::ElastiCache::User", {"UserName": "a"}, {"UserName": "b"}, "Always"),- ("AWS::ElastiCache::UserGroup", {"UserIds": ["a"]}, {"UserIds": ["b"]}, "Never"),-])-def test_cfn_elasticache_change_set_recreation(rtype, old, new, expected):- def tmpl(props):- return {"Resources": {"R": {"Type": rtype, "Properties": props}}}-- change = _diff_resources(tmpl(old), tmpl(new))[0]["ResourceChange"]- targets = {d["Target"]["Name"]: d["Target"]["RequiresRecreation"]- for d in change.get("Details", []) if d["Target"].get("Name")}- assert set(targets.values()) == {expected}---@requires_docker[email protected]_plane-def test_cfn_elasticache_lambda_reaches_replication_group(cfn, lam):- """The issue's use case: a stack passes PrimaryEndPoint into a function's- environment, and the function talks to the container behind it."""- s = _suffix()- stack = f"ec-lam-{s}"- code = (- "import os, socket\n"- "def handler(event, context):\n"- " s = socket.create_connection((os.environ['REDIS_HOST'], int(os.environ['REDIS_PORT'])), timeout=5)\n"- " s.sendall(b'PING\\r\\n')\n"- " reply = s.recv(64).decode()\n"- " s.close()\n"- " return {'reply': reply.strip()}\n"- )- _create(cfn, stack, {- "Resources": {- "Cache": {"Type": "AWS::ElastiCache::ReplicationGroup", "Properties": {- "ReplicationGroupDescription": "lambda", "Engine": "redis",- "CacheNodeType": "cache.t3.micro"}},- "Fn": {"Type": "AWS::Lambda::Function", "Properties": {- "FunctionName": f"ec-ping-{s}", "Runtime": "python3.12",- "Handler": "index.handler", "Role": _LAMBDA_ROLE, "Timeout": 15,- "Code": {"ZipFile": code},- "Environment": {"Variables": {- "REDIS_HOST": {"Fn::GetAtt": ["Cache", "PrimaryEndPoint.Address"]},- "REDIS_PORT": {"Fn::GetAtt": ["Cache", "PrimaryEndPoint.Port"]},- }}}},- },- })- try:- import time- deadline = time.time() + 60- while True:- resp = lam.invoke(FunctionName=f"ec-ping-{s}", Payload=b"{}")- result = json.loads(resp["Payload"].read())- if result.get("reply") == "+PONG" or time.time() > deadline:- break- time.sleep(1)- assert result.get("reply") == "+PONG", result- finally:- _delete(cfn, stack)diff --git a/tests/test_cfn_glue.py b/tests/test_cfn_glue.pydeleted file mode 100644index 3bd0428e..00000000--- a/tests/test_cfn_glue.py+++ /dev/null@@ -1,370 +0,0 @@-"""CloudFormation AWS::Glue::* resource types (#1875)."""--import json-import uuid--import pytest-from botocore.exceptions import ClientError--from ministack.services.cloudformation.stacks import _diff_resources--_ROLE = "arn:aws:iam::000000000000:role/glue-cfn-role"-_WAIT = {"Delay": 1, "MaxAttempts": 30}---def _suffix():- return uuid.uuid4().hex[:8]---def _create(cfn, name, template):- cfn.create_stack(StackName=name, TemplateBody=json.dumps(template))- cfn.get_waiter("stack_create_complete").wait(StackName=name, WaiterConfig=_WAIT)---def _update(cfn, name, template):- cfn.update_stack(StackName=name, TemplateBody=json.dumps(template))- cfn.get_waiter("stack_update_complete").wait(StackName=name, WaiterConfig=_WAIT)---def _delete(cfn, name):- cfn.delete_stack(StackName=name)- cfn.get_waiter("stack_delete_complete").wait(StackName=name, WaiterConfig=_WAIT)---def _outputs(cfn, name):- stack = cfn.describe_stacks(StackName=name)["Stacks"][0]- return {o["OutputKey"]: o["OutputValue"] for o in stack.get("Outputs", [])}---def _not_found(call):- with pytest.raises(ClientError) as exc:- call()- assert exc.value.response["Error"]["Code"] == "EntityNotFoundException"---def _glue_arn(sts, kind, name):- account = sts.get_caller_identity()["Account"]- return f"arn:aws:glue:us-east-1:{account}:{kind}/{name}"---def _data_lake(s, *, table_description="raw events", crawler_schedule=True,- job_tags=True, trigger_description="nightly", partition_location="p1"):- crawler = {- "Name": f"crawler-{s}",- "Role": _ROLE,- "DatabaseName": {"Ref": "Db"},- "Targets": {"S3Targets": [{"Path": f"s3://lake-{s}/events/"}]},- "Tags": {"team": "data"},- }- if crawler_schedule:- crawler["Schedule"] = {"ScheduleExpression": "cron(0 2 * * ? *)"}- job = {- "Name": f"job-{s}",- "Role": _ROLE,- "Command": {"Name": "pythonshell", "ScriptLocation": f"s3://lake-{s}/etl.py"},- "DefaultArguments": {"--stage": "dev"},- "MaxRetries": 1,- }- if job_tags:- job["Tags"] = [{"Key": "owner", "Value": "etl"}]- return {- "Resources": {- "Db": {- "Type": "AWS::Glue::Database",- "Properties": {- "CatalogId": {"Ref": "AWS::AccountId"},- "DatabaseInput": {"Name": f"lake_{s}", "Description": "data lake"},- },- },- "Events": {- "Type": "AWS::Glue::Table",- "Properties": {- "CatalogId": {"Ref": "AWS::AccountId"},- "DatabaseName": {"Ref": "Db"},- "TableInput": {- "Name": "events",- "Description": table_description,- "TableType": "EXTERNAL_TABLE",- "PartitionKeys": [{"Name": "dt", "Type": "string"}],- "StorageDescriptor": {- "Columns": [{"Name": "id", "Type": "string"}],- "Location": f"s3://lake-{s}/events/",- },- },- },- },- "Day": {- "Type": "AWS::Glue::Partition",- "Properties": {- "CatalogId": {"Ref": "AWS::AccountId"},- "DatabaseName": {"Ref": "Db"},- "TableName": {"Ref": "Events"},- "PartitionInput": {- "Values": ["2026-10-01"],- "StorageDescriptor": {"Location": f"s3://lake-{s}/events/{partition_location}/"},- },- },- },- "Jdbc": {- "Type": "AWS::Glue::Connection",- "Properties": {- "CatalogId": {"Ref": "AWS::AccountId"},- "ConnectionInput": {- "Name": f"conn-{s}",- "ConnectionType": "JDBC",- "ConnectionProperties": {"JDBC_CONNECTION_URL": "jdbc:postgresql://db:5432/app"},- },- },- },- "Crawler": {"Type": "AWS::Glue::Crawler", "Properties": crawler},- "Job": {"Type": "AWS::Glue::Job", "Properties": job},- "Trigger": {- "Type": "AWS::Glue::Trigger",- "Properties": {- "Name": f"trigger-{s}",- "Type": "SCHEDULED",- "Schedule": "cron(0 3 * * ? *)",- "Description": trigger_description,- "Actions": [{"JobName": {"Ref": "Job"}}],- },- },- },- "Outputs": {- key: {"Value": {"Ref": key}}- for key in ("Db", "Events", "Day", "Jdbc", "Crawler", "Job", "Trigger")- } | {- "JdbcName": {"Value": {"Fn::GetAtt": ["Jdbc", "Name"]}},- "DayValues": {"Value": {"Fn::GetAtt": ["Day", "IdentifierPartitionInputValues"]}},- },- }---def test_cfn_glue_data_lake_stack_create_and_delete(cfn, glue, sts):- s = _suffix()- stack = f"glue-lake-{s}"- _create(cfn, stack, _data_lake(s))- db, conn, crawler, job, trigger = f"lake_{s}", f"conn-{s}", f"crawler-{s}", f"job-{s}", f"trigger-{s}"-- out = _outputs(cfn, stack)- assert out["Db"] == db- assert out["Events"] == "events"- assert out["Jdbc"] == out["JdbcName"] == conn- assert out["Crawler"] == crawler- assert out["Job"] == job- assert out["Trigger"] == trigger- # The partition's Ref is its compound primary identifier joined with "|".- account = sts.get_caller_identity()["Account"]- assert out["Day"] == f"{account}|{db}|events|{out['DayValues']}"-- assert glue.get_database(Name=db)["Database"]["Description"] == "data lake"- table = glue.get_table(DatabaseName=db, Name="events")["Table"]- assert table["Description"] == "raw events"- assert table["PartitionKeys"] == [{"Name": "dt", "Type": "string"}]- partition = glue.get_partition(DatabaseName=db, TableName="events",- PartitionValues=["2026-10-01"])["Partition"]- assert partition["StorageDescriptor"]["Location"] == f"s3://lake-{s}/events/p1/"- assert glue.get_connection(Name=conn)["Connection"]["ConnectionType"] == "JDBC"- got_crawler = glue.get_crawler(Name=crawler)["Crawler"]- assert got_crawler["DatabaseName"] == db- assert got_crawler["Schedule"]["ScheduleExpression"] == "cron(0 2 * * ? *)"- assert glue.get_job(JobName=job)["Job"]["Command"]["Name"] == "pythonshell"- assert glue.get_trigger(Name=trigger)["Trigger"]["Actions"] == [{"JobName": job}]- # Tags given as a map (crawler) and as a Tag list (job) both land.- assert glue.get_tags(ResourceArn=_glue_arn(sts, "crawler", crawler))["Tags"] == {"team": "data"}- assert glue.get_tags(ResourceArn=_glue_arn(sts, "job", job))["Tags"] == {"owner": "etl"}-- _delete(cfn, stack)- _not_found(lambda: glue.get_database(Name=db))- _not_found(lambda: glue.get_table(DatabaseName=db, Name="events"))- _not_found(lambda: glue.get_connection(Name=conn))- _not_found(lambda: glue.get_crawler(Name=crawler))- _not_found(lambda: glue.get_job(JobName=job))- _not_found(lambda: glue.get_trigger(Name=trigger))---def test_cfn_glue_update_in_place(cfn, glue, sts):- s = _suffix()- stack = f"glue-upd-{s}"- _create(cfn, stack, _data_lake(s))- db, crawler, job, trigger = f"lake_{s}", f"crawler-{s}", f"job-{s}", f"trigger-{s}"- created = glue.get_table(DatabaseName=db, Name="events")["Table"]["CreateTime"]- try:- _update(cfn, stack, _data_lake(- s, table_description="cleaned events", crawler_schedule=False, job_tags=False,- trigger_description="hourly", partition_location="p2"))-- table = glue.get_table(DatabaseName=db, Name="events")["Table"]- assert table["Description"] == "cleaned events"- assert table["CreateTime"] == created- assert table["VersionId"] == "2"- partition = glue.get_partition(DatabaseName=db, TableName="events",- PartitionValues=["2026-10-01"])["Partition"]- assert partition["StorageDescriptor"]["Location"] == f"s3://lake-{s}/events/p2/"- # A property the template dropped is cleared, not left at its old value.- assert not glue.get_crawler(Name=crawler)["Crawler"].get("Schedule")- assert glue.get_tags(ResourceArn=_glue_arn(sts, "job", job))["Tags"] == {}- assert glue.get_trigger(Name=trigger)["Trigger"]["Description"] == "hourly"- finally:- _delete(cfn, stack)---def test_cfn_glue_table_rename_replaces(cfn, glue):- s = _suffix()- stack = f"glue-ren-{s}"- template = _data_lake(s)- _create(cfn, stack, template)- db = f"lake_{s}"- try:- template["Resources"]["Events"]["Properties"]["TableInput"]["Name"] = "events_v2"- # The partition follows its table through Ref, which replaces it too.- _update(cfn, stack, template)- assert _outputs(cfn, stack)["Events"] == "events_v2"- assert glue.get_table(DatabaseName=db, Name="events_v2")["Table"]["Name"] == "events_v2"- _not_found(lambda: glue.get_table(DatabaseName=db, Name="events"))- glue.get_partition(DatabaseName=db, TableName="events_v2", PartitionValues=["2026-10-01"])- finally:- _delete(cfn, stack)---def test_cfn_glue_partition_values_change_replaces(cfn, glue):- s = _suffix()- stack = f"glue-pv-{s}"- template = _data_lake(s)- _create(cfn, stack, template)- db = f"lake_{s}"- before = _outputs(cfn, stack)["Day"]- try:- template["Resources"]["Day"]["Properties"]["PartitionInput"]["Values"] = ["2026-10-02"]- _update(cfn, stack, template)- assert _outputs(cfn, stack)["Day"] != before- glue.get_partition(DatabaseName=db, TableName="events", PartitionValues=["2026-10-02"])- _not_found(lambda: glue.get_partition(- DatabaseName=db, TableName="events", PartitionValues=["2026-10-01"]))- finally:- _delete(cfn, stack)---def test_cfn_glue_database_input_name_change_updates_in_place(cfn, glue):- s = _suffix()- stack = f"glue-dbn-{s}"-- def template(name, description):- return {- "Resources": {"Db": {"Type": "AWS::Glue::Database", "Properties": {- "CatalogId": {"Ref": "AWS::AccountId"},- "DatabaseInput": {"Name": name, "Description": description}}}},- "Outputs": {"Db": {"Value": {"Ref": "Db"}}},- }-- _create(cfn, stack, template(f"first_{s}", "one"))- try:- # DatabaseName is the type's only create-only property, so the- # database is updated, not replaced, and keeps its Ref.- _update(cfn, stack, template(f"second_{s}", "two"))- assert _outputs(cfn, stack)["Db"] == f"first_{s}"- assert glue.get_database(Name=f"first_{s}")["Database"]["Description"] == "two"- _not_found(lambda: glue.get_database(Name=f"second_{s}"))- finally:- _delete(cfn, stack)---def test_cfn_glue_table_moves_database(cfn, glue):- s = _suffix()- stack = f"glue-mv-{s}"-- def template(db_ref):- return {"Resources": {- "A": {"Type": "AWS::Glue::Database", "Properties": {- "CatalogId": {"Ref": "AWS::AccountId"}, "DatabaseInput": {"Name": f"a_{s}"}}},- "B": {"Type": "AWS::Glue::Database", "Properties": {- "CatalogId": {"Ref": "AWS::AccountId"}, "DatabaseInput": {"Name": f"b_{s}"}}},- "T": {"Type": "AWS::Glue::Table", "Properties": {- "CatalogId": {"Ref": "AWS::AccountId"}, "DatabaseName": {"Ref": db_ref},- "TableInput": {"Name": "t"}}},- }}-- _create(cfn, stack, template("A"))- try:- _update(cfn, stack, template("B"))- glue.get_table(DatabaseName=f"b_{s}", Name="t")- _not_found(lambda: glue.get_table(DatabaseName=f"a_{s}", Name="t"))- finally:- _delete(cfn, stack)---def test_cfn_glue_named_trigger_type_change_is_refused(cfn, glue):- s = _suffix()- stack = f"glue-trg-{s}"-- def template(trigger_type):- props = {"Name": f"trigger-{s}", "Type": trigger_type,- "Actions": [{"JobName": f"job-{s}"}]}- if trigger_type == "SCHEDULED":- props["Schedule"] = "cron(0 3 * * ? *)"- return {"Resources": {"T": {"Type": "AWS::Glue::Trigger", "Properties": props}}}-- _create(cfn, stack, template("ON_DEMAND"))- try:- cfn.update_stack(StackName=stack, TemplateBody=json.dumps(template("SCHEDULED")))- with pytest.raises(Exception):- cfn.get_waiter("stack_update_complete").wait(StackName=stack, WaiterConfig=_WAIT)- events = cfn.describe_stack_events(StackName=stack)["StackEvents"]- reasons = [e.get("ResourceStatusReason", "") for e in events if e["LogicalResourceId"] == "T"]- assert any("custom-named resource requires replacing" in r for r in reasons)- assert glue.get_trigger(Name=f"trigger-{s}")["Trigger"]["Type"] == "ON_DEMAND"- finally:- _delete(cfn, stack)---def test_cfn_glue_generated_names(cfn, glue):- s = _suffix()- stack = f"Glue-Gen-{s}"- template = {- "Resources": {- "Db": {"Type": "AWS::Glue::Database", "Properties": {- "CatalogId": {"Ref": "AWS::AccountId"}, "DatabaseInput": {}}},- "Tbl": {"Type": "AWS::Glue::Table", "Properties": {- "CatalogId": {"Ref": "AWS::AccountId"}, "DatabaseName": {"Ref": "Db"},- "TableInput": {"TableType": "EXTERNAL_TABLE"}}},- "Job": {"Type": "AWS::Glue::Job", "Properties": {- "Role": _ROLE, "Command": {"Name": "pythonshell", "ScriptLocation": "s3://b/k.py"}}},- },- "Outputs": {k: {"Value": {"Ref": k}} for k in ("Db", "Tbl", "Job")},- }- _create(cfn, stack, template)- try:- out = _outputs(cfn, stack)- # Glue folds catalog names to lowercase, so generated ones start that way.- assert out["Db"] == out["Db"].lower() and out["Db"].startswith(f"glue-gen-{s}-db-")- assert out["Tbl"] == out["Tbl"].lower()- assert out["Job"].startswith(f"{stack}-Job-")- glue.get_table(DatabaseName=out["Db"], Name=out["Tbl"])- glue.get_job(JobName=out["Job"])- # An update under a generated name keeps the same resource.- template["Resources"]["Job"]["Properties"]["MaxRetries"] = 2- _update(cfn, stack, template)- assert _outputs(cfn, stack)["Job"] == out["Job"]- assert glue.get_job(JobName=out["Job"])["Job"]["MaxRetries"] == 2- finally:- _delete(cfn, stack)---# Expected values follow the createOnlyProperties of the published registry-# schemas; they were not observed on an AWS change set.[email protected]("rtype,old,new,expected", [- ("AWS::Glue::Database", {"DatabaseName": "a"}, {"DatabaseName": "b"}, "Always"),- ("AWS::Glue::Database", {"DatabaseInput": {"Name": "a"}}, {"DatabaseInput": {"Name": "b"}}, "Never"),- ("AWS::Glue::Job", {"Name": "a"}, {"Name": "b"}, "Always"),- ("AWS::Glue::Job", {"MaxRetries": 0}, {"MaxRetries": 1}, "Never"),- ("AWS::Glue::Trigger", {"Type": "ON_DEMAND"}, {"Type": "SCHEDULED"}, "Always"),- ("AWS::Glue::Crawler", {"Description": "a"}, {"Description": "b"}, "Never"),- ("AWS::Glue::Partition", {"TableName": "a"}, {"TableName": "b"}, "Conditionally"),-])-def test_cfn_glue_change_set_recreation(rtype, old, new, expected):- def tmpl(props):- return {"Resources": {"R": {"Type": rtype, "Properties": props}}}-- change = _diff_resources(tmpl(old), tmpl(new))[0]["ResourceChange"]- targets = {d["Target"]["Name"]: d["Target"]["RequiresRecreation"]- for d in change.get("Details", []) if d["Target"].get("Name")}- assert set(targets.values()) == {expected}diff --git a/tests/test_ec2.py b/tests/test_ec2.pyindex 26e14216..e01e0eb7 100644--- a/tests/test_ec2.py+++ b/tests/test_ec2.py@@ -1166,6 +1166,12 @@ def test_ec2_internet_gateway_crud(ec2):desc = ec2.describe_internet_gateways(InternetGatewayIds=[igw_id])assert len(desc["InternetGateways"][0]["Attachments"]) == 1+ other_vpc = ec2.create_vpc(CidrBlock="10.4.0.0/16")["Vpc"]["VpcId"]+ with pytest.raises(ClientError) as exc:+ ec2.attach_internet_gateway(InternetGatewayId=igw_id, VpcId=other_vpc)+ assert exc.value.response["Error"]["Code"] == "Resource.AlreadyAssociated"+ ec2.delete_vpc(VpcId=other_vpc)+ec2.detach_internet_gateway(InternetGatewayId=igw_id, VpcId=vpc_id)ec2.delete_internet_gateway(InternetGatewayId=igw_id)ec2.delete_vpc(VpcId=vpc_id)diff --git a/tests/test_eventbridge.py b/tests/test_eventbridge.pyindex 129276d3..a5e7b31f 100644--- a/tests/test_eventbridge.py+++ b/tests/test_eventbridge.py@@ -933,6 +933,21 @@ def test_eventbridge_create_event_bus_v2(eb):updated = eb.describe_event_bus(Name="eb-bus-v2")assert updated["Description"] == "updated description"+def test_eventbridge_update_event_bus_returns_bus(eb):+ created = eb.create_event_bus(Name="eb-bus-update-resp")+ try:+ resp = eb.update_event_bus(+ Name="eb-bus-update-resp",+ Description="new description",+ DeadLetterConfig={"Arn": "arn:aws:sqs:us-east-1:000000000000:eb-dlq"},+ )+ assert resp["Arn"] == created["EventBusArn"]+ assert resp["Name"] == "eb-bus-update-resp"+ assert resp["Description"] == "new description"+ assert resp["DeadLetterConfig"] == {"Arn": "arn:aws:sqs:us-east-1:000000000000:eb-dlq"}+ finally:+ eb.delete_event_bus(Name="eb-bus-update-resp")+def test_eventbridge_put_rule_v2(eb):eb.create_event_bus(Name="eb-rule-bus")resp = eb.put_rule(diff --git a/tests/test_iam_auth.py b/tests/test_iam_auth.pyindex 441e9022..4e7f7fc8 100644--- a/tests/test_iam_auth.py+++ b/tests/test_iam_auth.py@@ -2876,6 +2876,20 @@ class TestAccessDeniedResponse:message="Token expired")assert b"ExpiredTokenException" in b+ def test_ssm_denial_shape_applies_to_every_ssm_action(self):+ """Not only the tag actions: AWS answers e.g. GetParameters denials with+ HTTP 400 and the resource in the message."""+ from ministack.core.iam_actions import access_denied_response++ arn = "arn:aws:ssm:us-east-1:123456789012:parameter/app/db"+ status, headers, body = access_denied_response(+ "ssm", "ssm:GetParameter", "arn:aws:iam::123456789012:user/a", "r1", resource_arn=arn)+ assert status == 400+ assert headers["Content-Type"] == "application/x-amz-json-1.1"+ denied = json.loads(body)+ assert denied["__type"] == "AccessDeniedException"+ assert f"ssm:GetParameter on resource: {arn} because" in denied["Message"]+@pytest.mark.parametrize("action", ("AddTagsToResource", "RemoveTagsFromResource", "ListTagsForResource",))diff --git a/tests/test_inspector2.py b/tests/test_inspector2.pyindex d194bd54..7c8d3458 100644--- a/tests/test_inspector2.py+++ b/tests/test_inspector2.py@@ -3,6 +3,8 @@ Integration tests for the Inspector2 emulator."""+import json+import boto3import pytestfrom botocore.config import Config@@ -300,6 +302,30 @@ class TestPersistence:state2 = _inspector2.get_state()assert set(state.keys()) == set(state2.keys())+ def test_restore_migrates_legacy_shapes(self):+ from ministack.services import inspector2 as _inspector2++ saved = _inspector2.get_state()+ acct, iso = "000000000000", "2026-09-30T04:18:05+00:00"+ arn = f"arn:aws:inspector2:us-east-1:{acct}:owner/{acct}/filter/f1"+ try:+ _inspector2.load_persisted_state({+ "findings": {acct: [{"firstObservedAt": iso, "packageVulnerabilityDetails": {"vendorCreatedAt": iso}}]},+ "coverage": {acct: [{"lastScannedAt": iso, "scanStatus": {"code": "ACTIVE", "reason": "INITIAL_SCAN_COMPLETE"}}]},+ "filters": {acct: {"f1": {"arn": arn, "name": "f1", "action": "NONE", "findingCriteria": {"severity": []}}}},+ })+ state = _inspector2.get_state()+ finding = next(iter(state["findings"]._data.values()))[0]+ assert finding["firstObservedAt"] == 1790741885+ assert finding["packageVulnerabilityDetails"]["vendorCreatedAt"] == 1790741885+ coverage = next(iter(state["coverage"]._data.values()))[0]+ assert coverage["scanStatus"] == {"statusCode": "ACTIVE", "reason": "SUCCESSFUL"}+ filt = next(iter(state["filters"]._data.values()))["f1"]+ assert filt["criteria"] == {"severity": []} and "findingCriteria" not in filt+ assert filt["ownerId"] == acct and filt["createdAt"] == filt["updatedAt"]+ finally:+ _inspector2.load_persisted_state(saved)+class TestFindingsFiltering:def test_filter_by_severity(self, inspector2):@@ -911,3 +937,56 @@ class TestBatchGetFindingDetails:assert len(resp["findingDetails"]) == 0assert len(resp["errors"]) == 1assert resp["errors"][0]["errorCode"] == "RESOURCE_NOT_FOUND"+++def _raw_body(client, operation, method, **kwargs):+ """The JSON body MiniStack answered with, before botocore parses it."""+ captured = {}++ def grab(http_response, **_):+ captured["body"] = json.loads(http_response.content)++ event = f"after-call.inspector2.{operation}"+ client.meta.events.register(event, grab)+ try:+ getattr(client, method)(**kwargs)+ finally:+ client.meta.events.unregister(event, grab)+ return captured["body"]+++class TestSdkShapes:+ def test_timestamps_are_epoch_seconds(self, inspector2):+ inspector2.enable(resourceTypes=["ECR"])+ findings = _raw_body(inspector2, "ListFindings", "list_findings")["findings"]+ assert findings+ for key in ("firstObservedAt", "lastObservedAt", "updatedAt"):+ assert isinstance(findings[0][key], (int, float)), key+ covered = _raw_body(inspector2, "ListCoverage", "list_coverage")["coveredResources"]+ assert covered+ assert isinstance(covered[0]["lastScannedAt"], (int, float))++ def test_list_coverage_scan_status_code(self, inspector2):+ inspector2.enable(resourceTypes=["ECR"])+ inspector2.list_findings()+ status = inspector2.list_coverage()["coveredResources"][0]["scanStatus"]+ assert status["statusCode"] == "ACTIVE"+ assert status["reason"] == "SUCCESSFUL"+ filtered = inspector2.list_coverage(+ filterCriteria={"scanStatusCode": [{"comparison": "EQUALS", "value": "ACTIVE"}]}+ )["coveredResources"]+ assert filtered++ def test_list_filters_returns_filter_shape(self, inspector2):+ criteria = {"severity": [{"comparison": "EQUALS", "value": "HIGH"}]}+ created = inspector2.create_filter(name="sdk-shape-filter", action="NONE", filterCriteria=criteria)+ try:+ listed = [f for f in inspector2.list_filters()["filters"] if f["arn"] == created["arn"]]+ assert len(listed) == 1+ filt = listed[0]+ assert filt["criteria"] == criteria+ assert "findingCriteria" not in filt+ assert filt["ownerId"]+ assert filt["createdAt"] and filt["updatedAt"]+ finally:+ inspector2.delete_filter(arn=created["arn"])diff --git a/tests/test_iot.py b/tests/test_iot.pyindex f77211ca..89fc022a 100644--- a/tests/test_iot.py+++ b/tests/test_iot.py@@ -5690,7 +5690,10 @@ def _registry_events(calls, enable=_EVENT_TYPES) -> list:for _topic, event in received:assert re.fullmatch(r"[0-9a-f]{32}", event["eventId"])assert isinstance(event.pop("timestamp"), int)- assert event.pop("accountId") == _EVENTS_ACCOUNT+ if event["eventType"] == "THING_TYPE_ASSOCIATION_EVENT":+ assert "accountId" not in event+ else:+ assert event.pop("accountId") == _EVENTS_ACCOUNTreturn receiveddiff --git a/tests/test_lambda.py b/tests/test_lambda.pyindex 7e218d43..7057b707 100644--- a/tests/test_lambda.py+++ b/tests/test_lambda.py@@ -518,6 +518,7 @@ def test_lambda_direct_arn_version_delete_rejects_weighted_alias_version():Code={"ZipFile": _region_marker_code("latest")},)primary = lam.publish_version(FunctionName=name)+ lam.update_function_code(FunctionName=name, ZipFile=_region_marker_code("weighted"))weighted = lam.publish_version(FunctionName=name)lam.create_alias(FunctionName=name,@@ -1269,6 +1270,22 @@ def test_lambda_list_versions(lam):versions = resp["Versions"]assert any(v["Version"] == "$LATEST" for v in versions)+def test_lambda_publish_version_of_an_unchanged_function_returns_the_latest(lam):+ """Lambda doesn't publish a version when code and configuration are unchanged."""+ name = f"lambda-publish-unchanged-{_uuid_mod.uuid4().hex[:8]}"+ lam.create_function(FunctionName=name, Runtime="python3.12", Role=_LAMBDA_ROLE,+ Handler="index.handler", Code={"ZipFile": _region_marker_code("one")})+ try:+ first = lam.publish_version(FunctionName=name, Description="one")+ again = lam.publish_version(FunctionName=name, Description="two")+ assert (again["Version"], again["Description"]) == (first["Version"], "one")+ lam.update_function_code(FunctionName=name, ZipFile=_region_marker_code("two"))+ second = lam.publish_version(FunctionName=name)+ assert int(second["Version"]) == int(first["Version"]) + 1+ finally:+ lam.delete_function(FunctionName=name)++def test_lambda_publish_version(lam):resp = lam.publish_version(FunctionName="lam-invoke-test",diff --git a/tests/test_mq.py b/tests/test_mq.pyindex 6165871a..55e42530 100644--- a/tests/test_mq.py+++ b/tests/test_mq.py@@ -506,6 +506,20 @@ def test_mq_describe_broker_instance_options(mq):assert "SupportedEngineVersions" in optionassert "SupportedDeploymentModes" in option+def test_mq_describe_broker_instance_options_engine_versions_are_strings(mq):+ # SupportedEngineVersions is a list of strings; only DescribeBrokerEngineTypes+ # wraps each version in an object with a Name.+ engine_versions = {+ e["EngineType"]: sorted(v["Name"] for v in e["EngineVersions"])+ for e in mq.describe_broker_engine_types()["BrokerEngineTypes"]+ }+ options = mq.describe_broker_instance_options()["BrokerInstanceOptions"]+ assert options+ for option in options:+ versions = option["SupportedEngineVersions"]+ assert all(isinstance(v, str) for v in versions), versions+ assert sorted(versions) == engine_versions[option["EngineType"]]+@pytest.mark.parametrize("kwargs,assertions",[diff --git a/tests/test_rds.py b/tests/test_rds.pyindex 3f6bf830..61bc5fd1 100644--- a/tests/test_rds.py+++ b/tests/test_rds.py@@ -864,6 +864,37 @@ def test_rds_global_cluster_lifecycle(rds):rds.describe_global_clusters(GlobalClusterIdentifier="test-global-1")assert exc.value.response["Error"]["Code"] == "GlobalClusterNotFoundFault"+def test_rds_describe_global_clusters_member_element(rds):+ """Each cluster in DescribeGlobalClusters is a <GlobalClusterMember> element.++ botocore reads the items of a list whatever their element name, so boto3+ cannot tell; SDKs that match the name, such as aws-sdk-go-v2, found no+ clusters when they were <GlobalCluster> elements.+ """+ import xml.etree.ElementTree as ET++ import requests+ rds.create_global_cluster(+ GlobalClusterIdentifier="test-global-wire",+ Engine="aurora-postgresql",+ EngineVersion="15.13",+ )+ try:+ response = requests.post(+ ENDPOINT,+ data={"Action": "DescribeGlobalClusters", "Version": "2014-10-31",+ "GlobalClusterIdentifier": "test-global-wire"},+ headers={"Authorization": "AWS4-HMAC-SHA256 "+ "Credential=test/20260930/us-east-1/rds/aws4_request"},+ timeout=10,+ )+ assert response.status_code == 200+ clusters = ET.fromstring(response.content).find(".//{*}GlobalClusters")+ assert [child.tag.rpartition("}")[2] for child in clusters] == ["GlobalClusterMember"]+ assert clusters[0].findtext("{*}GlobalClusterIdentifier") == "test-global-wire"+ finally:+ rds.delete_global_cluster(GlobalClusterIdentifier="test-global-wire")+def test_rds_global_cluster_with_source(rds):"""CreateGlobalCluster with SourceDBClusterIdentifier picks up engine from source."""rds.create_db_cluster(diff --git a/tests/test_servicediscovery.py b/tests/test_servicediscovery.pyindex 14d394e9..e6ba7aa9 100644--- a/tests/test_servicediscovery.py+++ b/tests/test_servicediscovery.py@@ -375,6 +375,23 @@ def test_servicediscovery_delete_namespace_removes_hosted_zone(sd, r53):r53.get_hosted_zone(Id=zone_id)+def test_servicediscovery_delete_namespace_with_services_is_refused(sd, r53):+ ns_op = sd.create_public_dns_namespace(Name="in-use.example.com")+ ns_id = sd.get_operation(OperationId=ns_op["OperationId"])["Operation"]["Targets"]["NAMESPACE"]+ zone_id = sd.get_namespace(Id=ns_id)["Namespace"]["Properties"]["DnsProperties"]["HostedZoneId"]+ svc_id = sd.create_service(Name="api", NamespaceId=ns_id)["Service"]["Id"]++ with pytest.raises(sd.exceptions.ResourceInUse) as exc:+ sd.delete_namespace(Id=ns_id)+ assert exc.value.response["Error"]["Code"] == "ResourceInUse"+ assert exc.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400+ sd.get_namespace(Id=ns_id)+ r53.get_hosted_zone(Id=zone_id)++ sd.delete_service(Id=svc_id)+ sd.delete_namespace(Id=ns_id)++# ---------------------------------------------------------------------------# ARN adoption / tag-API in-process unit tests. Folded from# test_servicediscovery_arn_adoption.py (drive the module directly).diff --git a/tests/test_stepfunctions.py b/tests/test_stepfunctions.pyindex cadb31d2..d1a7023f 100644--- a/tests/test_stepfunctions.py+++ b/tests/test_stepfunctions.py@@ -8549,3 +8549,123 @@ def test_direct_secret_binary_sdk_keeps_arbitrary_bytes(sm):assert result["VersionId"] == updated["VersionId"]finally:sm.delete_secret(SecretId=name, ForceDeleteWithoutRecovery=True)+++ 'rule',+ [+ {'Variable': '$$.Execution.Input.marker', 'IsPresent': True},+ {'Variable': '$$.Execution.Input.missing', 'IsPresent': False},+ {'Variable': '$$.Execution.Input.marker', 'StringEquals': 'keep'},+ {'And': [+ {'Variable': '$$.Execution.Input.marker', 'IsPresent': True},+ {'Or': [+ {'Variable': '$.marker', 'StringEquals': 'wrong'},+ {'Not': {'Variable': '$$.Execution.Input.marker', 'StringEquals': 'wrong'}},+ ]},+ ]},+ {'Variable': '$.marker', 'StringEqualsPath': '$$.Execution.Input.marker'},+ {'Variable': '$$.Execution.Input.marker', 'StringEqualsPath': '$.marker'},+ {'Variable': '$$.Execution.Input.marker', 'StringEqualsPath': '$$.Execution.Input.marker'},+ {'Variable': '$.number', 'NumericEqualsPath': '$$.Execution.Input.number'},+ {'Variable': '$.number', 'NumericLessThanPath': '$$.Execution.Input.higher'},+ {'Variable': '$.number', 'NumericGreaterThanPath': '$$.Execution.Input.lower'},+ {'Variable': '$.number', 'NumericLessThanEqualsPath': '$$.Execution.Input.number'},+ {'Variable': '$.number', 'NumericGreaterThanEqualsPath': '$$.Execution.Input.number'},+ {'Variable': '$.enabled', 'BooleanEqualsPath': '$$.Execution.Input.enabled'},+ ],+)+def test_choice_context_rules(rule):+ from ministack.services import stepfunctions++ data = {'marker': 'keep', 'number': 5, 'enabled': True}+ ctx = {'Execution': {'Input': {**data, 'lower': 4, 'higher': 6}}}+ assert stepfunctions._evaluate_rule(rule, data, ctx)+ assert stepfunctions._execute_choice(+ {'InputPath': '$.projected', 'Choices': [{**rule, 'Next': 'Match'}], 'Default': 'Miss'},+ {'projected': data, 'marker': 'wrong', 'number': 0, 'enabled': False},+ ctx,+ ) == (data, 'Match')+++def test_choice_context_missing_and_data_paths():+ from ministack.services import stepfunctions++ assert not stepfunctions._evaluate_rule({'Variable': '$$.Execution.Id', 'IsPresent': True}, {})+ assert stepfunctions._evaluate_rule({'Variable': '$.value', 'NumericEqualsPath': '$.other'},+ {'value': 5, 'other': 5})+ assert not stepfunctions._evaluate_rule({'Variable': '$$.Execution.Input.marker', 'StringEquals': 'wrong'},+ {}, {'Execution': {'Input': {'marker': 'keep'}}})+++def test_choice_context_survives_input_replacement(sfn):+ definition = {+ 'StartAt': 'Replace',+ 'States': {+ 'Replace': {'Type': 'Pass', 'Result': {'projected': {'marker': 'keep'}}, 'Next': 'Check'},+ 'Check': {+ 'Type': 'Choice', 'InputPath': '$.projected',+ 'Choices': [{'And': [+ {'Variable': '$$.Execution.Input.marker', 'IsPresent': True},+ {'Variable': '$.marker', 'StringEqualsPath': '$$.Execution.Input.marker'},+ {'Variable': '$$.State.Name', 'StringEquals': 'Check'},+ ], 'Next': 'Match'}],+ 'Default': 'Miss',+ },+ 'Match': {'Type': 'Succeed'},+ 'Miss': {'Type': 'Fail', 'Error': 'ContextNotResolved'},+ },+ }+ arn = sfn.create_state_machine(name=f'choice-context-{_uuid_mod.uuid4().hex}',+ definition=json.dumps(definition),+ roleArn='arn:aws:iam::000000000000:role/R')['stateMachineArn']+ try:+ execution = sfn.start_execution(stateMachineArn=arn, input=json.dumps({'marker': 'keep'}))['executionArn']+ for _ in range(100):+ result = sfn.describe_execution(executionArn=execution)+ if result['status'] != 'RUNNING':+ break+ time.sleep(0.1)+ assert result['status'] == 'SUCCEEDED', result+ assert json.loads(result['output']) == {'marker': 'keep'}+ finally:+ sfn.delete_state_machine(stateMachineArn=arn)+++def test_context_paths_in_input_output_and_items_path(sfn):+ """InputPath, OutputPath and ItemsPath read `$$.` from the context object."""+ definition = {+ 'StartAt': 'Replace',+ 'States': {+ 'Replace': {'Type': 'Pass', 'Result': {'replaced': True}, 'Next': 'FromContext'},+ 'FromContext': {'Type': 'Pass', 'InputPath': '$$.Execution.Input', 'Next': 'Each'},+ 'Each': {+ 'Type': 'Map', 'ItemsPath': '$$.Execution.Input.items',+ 'ItemProcessor': {'StartAt': 'Item', 'States': {'Item': {'Type': 'Pass', 'End': True}}},+ 'ResultPath': '$.mapped', 'Next': 'Out',+ },+ 'Out': {'Type': 'Pass', 'OutputPath': '$$.State.Name', 'End': True},+ },+ }+ arn = sfn.create_state_machine(name=f'ctx-paths-{_uuid_mod.uuid4().hex}',+ definition=json.dumps(definition),+ roleArn='arn:aws:iam::000000000000:role/R')['stateMachineArn']+ try:+ execution = sfn.start_execution(stateMachineArn=arn,+ input=json.dumps({'items': [1, 2]}))['executionArn']+ for _ in range(100):+ result = sfn.describe_execution(executionArn=execution)+ if result['status'] != 'RUNNING':+ break+ time.sleep(0.1)+ assert result['status'] == 'SUCCEEDED', result+ assert json.loads(result['output']) == 'Out'+ history = sfn.get_execution_history(executionArn=execution)['events']+ each_input = next(json.loads(e['stateEnteredEventDetails']['input']) for e in history+ if e.get('stateEnteredEventDetails', {}).get('name') == 'Each')+ assert each_input == {'items': [1, 2]}+ out_input = next(json.loads(e['stateEnteredEventDetails']['input']) for e in history+ if e.get('stateEnteredEventDetails', {}).get('name') == 'Out')+ assert out_input['mapped'] == [1, 2]+ finally:+ sfn.delete_state_machine(stateMachineArn=arn)diff --git a/tests/test_stepfunctions_choice_context.py b/tests/test_stepfunctions_choice_context.pydeleted file mode 100644index b89665bb..00000000--- a/tests/test_stepfunctions_choice_context.py+++ /dev/null@@ -1,84 +0,0 @@-import json-import time-import uuid--import pytest--from ministack.services import stepfunctions--- 'rule',- [- {'Variable': '$$.Execution.Input.marker', 'IsPresent': True},- {'Variable': '$$.Execution.Input.missing', 'IsPresent': False},- {'Variable': '$$.Execution.Input.marker', 'StringEquals': 'keep'},- {'And': [- {'Variable': '$$.Execution.Input.marker', 'IsPresent': True},- {'Or': [- {'Variable': '$.marker', 'StringEquals': 'wrong'},- {'Not': {'Variable': '$$.Execution.Input.marker', 'StringEquals': 'wrong'}},- ]},- ]},- {'Variable': '$.marker', 'StringEqualsPath': '$$.Execution.Input.marker'},- {'Variable': '$$.Execution.Input.marker', 'StringEqualsPath': '$.marker'},- {'Variable': '$$.Execution.Input.marker', 'StringEqualsPath': '$$.Execution.Input.marker'},- {'Variable': '$.number', 'NumericEqualsPath': '$$.Execution.Input.number'},- {'Variable': '$.number', 'NumericLessThanPath': '$$.Execution.Input.higher'},- {'Variable': '$.number', 'NumericGreaterThanPath': '$$.Execution.Input.lower'},- {'Variable': '$.number', 'NumericLessThanEqualsPath': '$$.Execution.Input.number'},- {'Variable': '$.number', 'NumericGreaterThanEqualsPath': '$$.Execution.Input.number'},- {'Variable': '$.enabled', 'BooleanEqualsPath': '$$.Execution.Input.enabled'},- ],-)-def test_choice_context_rules(rule):- data = {'marker': 'keep', 'number': 5, 'enabled': True}- ctx = {'Execution': {'Input': {**data, 'lower': 4, 'higher': 6}}}- assert stepfunctions._evaluate_rule(rule, data, ctx)- assert stepfunctions._execute_choice(- {'InputPath': '$.projected', 'Choices': [{**rule, 'Next': 'Match'}], 'Default': 'Miss'},- {'projected': data, 'marker': 'wrong', 'number': 0, 'enabled': False},- ctx,- ) == (data, 'Match')---def test_choice_context_missing_and_data_paths():- assert not stepfunctions._evaluate_rule({'Variable': '$$.Execution.Id', 'IsPresent': True}, {})- assert stepfunctions._evaluate_rule({'Variable': '$.value', 'NumericEqualsPath': '$.other'},- {'value': 5, 'other': 5})- assert not stepfunctions._evaluate_rule({'Variable': '$$.Execution.Input.marker', 'StringEquals': 'wrong'},- {}, {'Execution': {'Input': {'marker': 'keep'}}})---def test_choice_context_survives_input_replacement(sfn):- definition = {- 'StartAt': 'Replace',- 'States': {- 'Replace': {'Type': 'Pass', 'Result': {'projected': {'marker': 'keep'}}, 'Next': 'Check'},- 'Check': {- 'Type': 'Choice', 'InputPath': '$.projected',- 'Choices': [{'And': [- {'Variable': '$$.Execution.Input.marker', 'IsPresent': True},- {'Variable': '$.marker', 'StringEqualsPath': '$$.Execution.Input.marker'},- {'Variable': '$$.State.Name', 'StringEquals': 'Check'},- ], 'Next': 'Match'}],- 'Default': 'Miss',- },- 'Match': {'Type': 'Succeed'},- 'Miss': {'Type': 'Fail', 'Error': 'ContextNotResolved'},- },- }- arn = sfn.create_state_machine(name=f'choice-context-{uuid.uuid4().hex}',- definition=json.dumps(definition),- roleArn='arn:aws:iam::000000000000:role/R')['stateMachineArn']- try:- execution = sfn.start_execution(stateMachineArn=arn, input=json.dumps({'marker': 'keep'}))['executionArn']- for _ in range(100):- result = sfn.describe_execution(executionArn=execution)- if result['status'] != 'RUNNING':- break- time.sleep(0.1)- assert result['status'] == 'SUCCEEDED', result- assert json.loads(result['output']) == {'marker': 'keep'}- finally:- sfn.delete_state_machine(stateMachineArn=arn)