Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
fix(s3): accept the legacy EU location constraint for eu-west-1 (#2334)
Toby Nelsona1237c98c64c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 24a8fc7e..9beb9a79 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).- **Route 53 — VPC associations for private hosted zones** — `AssociateVPCWithHostedZone`, `DisassociateVPCFromHostedZone` and `ListHostedZonesByVPC` (paged with `MaxItems` and `NextToken`). They refuse a public zone (`PublicZoneVPCAssociation`), a VPC already associated with a zone of the same name (`ConflictingDomainExists`), a VPC the zone doesn't have (404 `VPCAssociationNotFound`) and the zone's last VPC (`LastVPCAssociation`). Contributed by @kharabasz.### Fixed+- **S3 — `EU` location constraint** — since 1.5.28, `CreateBucket` from an eu-west-1 endpoint refused the legacy `EU` constraint with `IllegalLocationConstraintException`, and a bucket created with it elsewhere was homed in a region called `EU`. As on AWS, eu-west-1 now accepts `EU` and homes the bucket in eu-west-1, `GetBucketLocation` answers `EU` for it, and other regional endpoints still refuse it. The AWS SDK for .NET sends `EU` for eu-west-1 by default.- **WAF v2 — `CreateIPSet` and `CreateRuleGroup` refuse a duplicate name** — a second IP set or rule group with the name and scope of an existing one is now refused with `WAFDuplicateItemException`, as AWS does and as `CreateWebACL` and `CreateRegexPatternSet` already did. Both stored the duplicate silently, so a client that retries a create after losing the response ended up with two. Contributed by @OS-kiranmalsetty.- **Route 53 — private hosted zones keep their VPC** — `CreateHostedZone` with a `VPC` made a public zone and dropped the VPC, so Terraform's `aws_route53_zone` with a `vpc` block planned to add it again on every run; the zone is now private, the response carries the `VPC` instead of a delegation set, also on a `CallerReference` replay, and `GetHostedZone` returns its `VPCs`. Contributed by @kharabasz.- **ELBv2 — listener `SslPolicy` and certificate** — `CreateListener` and `ModifyListener` dropped `SslPolicy` and `Certificates`, so `DescribeListeners` returned neither and Terraform re-planned `ssl_policy` on every HTTPS listener; HTTPS and TLS listeners now keep and return both, the policy defaults to `ELBSecurityPolicy-2016-08`, a listener moved to HTTP or TCP drops them, and more than one default certificate answers `ValidationError`. Contributed by @kharabasz.diff --git a/ministack/services/s3.py b/ministack/services/s3.pyindex dac00143..a9c27666 100644--- a/ministack/services/s3.py+++ b/ministack/services/s3.py@@ -2715,6 +2715,12 @@ def _location_constraint(body: bytes) -> str | None:return loc_el.text if loc_el is not None and loc_el.text else None+def _constraint_region(constraint: str | None) -> str | None:+ """``EU`` is the legacy LocationConstraint for eu-west-1, which still+ accepts it (observed on AWS 2026-10-20); the AWS SDK for .NET sends it."""+ return "eu-west-1" if constraint == "EU" else constraint++def _location_constraint_error(name: str, constraint: str | None, endpoint_region: str):"""CreateBucket's location-constraint rules for a request signed for``endpoint_region`` (observed on AWS 2026-10-12): us-east-1 is never a@@ -2723,7 +2729,7 @@ def _location_constraint_error(name: str, constraint: str | None, endpoint_regioif constraint == "us-east-1":return _error("InvalidLocationConstraint", "The specified location-constraint is not valid",400, f"/{name}", extra={"LocationConstraint": constraint})- if endpoint_region != "us-east-1" and constraint != endpoint_region:+ if endpoint_region != "us-east-1" and _constraint_region(constraint) != endpoint_region:return _error("IllegalLocationConstraintException",f"The {constraint or 'unspecified'} location constraint is incompatible for the region "@@ -2781,14 +2787,14 @@ def _create_bucket(name: str, body: bytes, headers: dict = None, endpoint_regionextra={"BucketName": name},)- region = None+ constraint = Nonetags = {}if body:try:xml_root = fromstring(body)loc_el = _find_xml_tag(xml_root, "LocationConstraint")if loc_el is not None and loc_el.text:- region = loc_el.text+ constraint = loc_el.texterr = _duplicate_tag_error(xml_root, resource=f"/{name}")if err is not None:@@ -2804,8 +2810,11 @@ def _create_bucket(name: str, body: bytes, headers: dict = None, endpoint_region# No explicit LocationConstraint: the bucket lands in the region the# request was signed for, like real AWS.- region = region or get_region()+ region = _constraint_region(constraint) or get_region()_buckets[name] = {"created": now_iso(), "objects": {}, "region": region}+ if constraint == "EU":+ # GetBucketLocation answers EU for a bucket created with EU (observed on AWS 2026-10-20).+ _buckets[name]["location_constraint"] = constraintownership = headers.get("x-amz-object-ownership")if ownership:# The same document PutBucketOwnershipControls stores.@@ -2906,7 +2915,7 @@ def _get_bucket_location(name: str):# AWS returns an empty LocationConstraint only for us-east-1 buckets;# every other region is echoed back verbatim.if region != "us-east-1":- root.text = region+ root.text = _buckets[name].get("location_constraint") or regionreturn 200, {"Content-Type": "application/xml"}, _xml_body(root)diff --git a/tests/test_s3.py b/tests/test_s3.pyindex c24aa834..b0768337 100644--- a/tests/test_s3.py+++ b/tests/test_s3.py@@ -877,6 +877,29 @@ def test_s3_location_constraint_required_outside_us_east_1(s3):euw1.delete_bucket(Bucket=bkt)+def test_s3_location_constraint_eu_is_eu_west_1(s3):+ """EU is the legacy LocationConstraint for eu-west-1: eu-west-1 accepts it+ and GetBucketLocation answers EU, other regional endpoints refuse it+ (observed on AWS 2026-10-20)."""+ euw1 = _regional_client("s3", "eu-west-1")+ bkt = f"intg-s3-loc-eu-{_uuid_mod.uuid4().hex[:8]}"+ euw1.create_bucket(Bucket=bkt, CreateBucketConfiguration={"LocationConstraint": "EU"})+ try:+ assert euw1.get_bucket_location(Bucket=bkt)["LocationConstraint"] == "EU"+ euw1.put_object(Bucket=bkt, Key="k", Body=b"x")+ assert euw1.get_object(Bucket=bkt, Key="k")["Body"].read() == b"x"+ finally:+ euw1.delete_object(Bucket=bkt, Key="k")+ euw1.delete_bucket(Bucket=bkt)++ euc1 = _regional_client("s3", "eu-central-1")+ resp = _create_bucket_error(euc1, Bucket=f"intg-s3-loc-eu-c1-{_uuid_mod.uuid4().hex[:8]}",+ CreateBucketConfiguration={"LocationConstraint": "EU"})+ assert resp["Error"]["Code"] == "IllegalLocationConstraintException"+ assert resp["Error"]["Message"] == ("The EU location constraint is incompatible for the "+ "region specific endpoint this request was sent to.")++def test_s3_location_constraint_us_east_1_is_invalid(s3):bkt = f"intg-s3-loc-use1-{_uuid_mod.uuid4().hex[:8]}"for client in (s3, _regional_client("s3", "eu-west-1")):