Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(bugs): tf v6, ddb, lambda recursive (#1290)

Nahuel Nuceraee56fd7da7ba
diff --git a/ministack/services/dynamodb.py b/ministack/services/dynamodb.py
index 0fd1d152..05e92178 100644
--- a/ministack/services/dynamodb.py
+++ b/ministack/services/dynamodb.py
@@ -1945,7 +1945,12 @@ def _query(data):
scan_forward = data.get("ScanIndexForward", True)
esk = data.get("ExclusiveStartKey")
index_name = data.get("IndexName")
- select = data.get("Select", "ALL_ATTRIBUTES")
+ # A ProjectionExpression / AttributesToGet without an explicit Select is
+ # equivalent to Select=SPECIFIC_ATTRIBUTES (AWS Query docs); only default to
+ # ALL_ATTRIBUTES when no projection is requested.
+ select = data.get("Select")
+ if select is None:
+ select = "SPECIFIC_ATTRIBUTES" if (data.get("ProjectionExpression") or data.get("AttributesToGet")) else "ALL_ATTRIBUTES"
if key_cond and key_conditions:
return error_response_json("ValidationException", "Can not use both expression and non-expression parameters in the same request: Non-expression parameters: {KeyConditions} Expression parameters: {KeyConditionExpression}", 400)
@@ -2222,7 +2227,12 @@ def _scan(data):
limit = data.get("Limit")
esk = data.get("ExclusiveStartKey")
index_name = data.get("IndexName")
- select = data.get("Select", "ALL_ATTRIBUTES")
+ # A ProjectionExpression / AttributesToGet without an explicit Select is
+ # equivalent to Select=SPECIFIC_ATTRIBUTES (AWS Scan docs); only default to
+ # ALL_ATTRIBUTES when no projection is requested.
+ select = data.get("Select")
+ if select is None:
+ select = "SPECIFIC_ATTRIBUTES" if (data.get("ProjectionExpression") or data.get("AttributesToGet")) else "ALL_ATTRIBUTES"
# Limit must be > 0 when provided (AWS rejects Limit=0).
if limit is not None and int(limit) <= 0:
diff --git a/ministack/services/lambda_svc.py b/ministack/services/lambda_svc.py
index cb473211..b37a8626 100644
--- a/ministack/services/lambda_svc.py
+++ b/ministack/services/lambda_svc.py
@@ -1718,6 +1718,13 @@ async def handle_request(method: str, path: str, headers: dict, body: bytes, que
if method == "DELETE":
return _delete_function_concurrency(func_name)
+ # --- Recursion Config ---
+ if sub == "recursion-config":
+ if method == "GET":
+ return _get_function_recursion_config(func_name)
+ if method == "PUT":
+ return _put_function_recursion_config(func_name, data)
+
# GetFunction
if method == "GET" and not sub:
qualifier = _qualifier_from_path_or_query(path_qualifier, query_params)
@@ -5264,6 +5271,40 @@ def _delete_function_concurrency(func_name: str):
return 204, {}, b""
+# ---------------------------------------------------------------------------
+# Recursion Config
+# ---------------------------------------------------------------------------
+
+
+def _get_function_recursion_config(func_name: str):
+ if func_name not in _functions:
+ return error_response_json(
+ "ResourceNotFoundException",
+ f"Function not found: {_func_arn(func_name)}",
+ 404,
+ )
+ loop = _functions[func_name].get("recursive_loop", "Terminate")
+ return json_response({"RecursiveLoop": loop})
+
+
+def _put_function_recursion_config(func_name: str, data: dict):
+ if func_name not in _functions:
+ return error_response_json(
+ "ResourceNotFoundException",
+ f"Function not found: {_func_arn(func_name)}",
+ 404,
+ )
+ value = data.get("RecursiveLoop")
+ if value not in ("Allow", "Terminate"):
+ return error_response_json(
+ "InvalidParameterValueException",
+ "RecursiveLoop must be one of: Allow, Terminate",
+ 400,
+ )
+ _functions[func_name]["recursive_loop"] = value
+ return json_response({"RecursiveLoop": value})
+
+
# ---------------------------------------------------------------------------
# Provisioned Concurrency (stubs)
# ---------------------------------------------------------------------------
diff --git a/ministack/services/s3.py b/ministack/services/s3.py
index 2b0e9bea..fea59ea0 100644
--- a/ministack/services/s3.py
+++ b/ministack/services/s3.py
@@ -1308,12 +1308,22 @@ def _get_bucket_lifecycle(name: str):
xml += f"<Prefix>{_esc(filt['Prefix'])}</Prefix>"
if "Tag" in filt:
xml += f"<Tag><Key>{_esc(filt['Tag']['Key'])}</Key><Value>{_esc(filt['Tag']['Value'])}</Value></Tag>"
+ if "ObjectSizeGreaterThan" in filt:
+ xml += f"<ObjectSizeGreaterThan>{filt['ObjectSizeGreaterThan']}</ObjectSizeGreaterThan>"
+ if "ObjectSizeLessThan" in filt:
+ xml += f"<ObjectSizeLessThan>{filt['ObjectSizeLessThan']}</ObjectSizeLessThan>"
if "And" in filt:
+ and_f = filt["And"]
xml += "<And>"
- if "Prefix" in filt["And"]:
- xml += f"<Prefix>{_esc(filt['And']['Prefix'])}</Prefix>"
- for tag in filt["And"].get("Tags", []):
+ # AWS always echoes Prefix (empty when unset) and ObjectSizeGreaterThan
+ # (0 when unset) inside an And operator; omitting either breaks the
+ # aws-sdk-go equality waiter (the provider expands them as "" / 0).
+ xml += f"<Prefix>{_esc(and_f.get('Prefix', ''))}</Prefix>"
+ for tag in and_f.get("Tags", []):
xml += f"<Tag><Key>{_esc(tag['Key'])}</Key><Value>{_esc(tag['Value'])}</Value></Tag>"
+ xml += f"<ObjectSizeGreaterThan>{and_f.get('ObjectSizeGreaterThan', 0)}</ObjectSizeGreaterThan>"
+ if and_f.get("ObjectSizeLessThan"):
+ xml += f"<ObjectSizeLessThan>{and_f['ObjectSizeLessThan']}</ObjectSizeLessThan>"
xml += "</And>"
xml += "</Filter>"
xml += f"<Status>{rule.get('Status', 'Enabled')}</Status>"
@@ -1401,6 +1411,12 @@ def _put_bucket_lifecycle(name: str, body: bytes):
tag_el = _lc_find(filt_el, "Tag")
if tag_el is not None:
filt["Tag"] = {"Key": _lc_text(tag_el, "Key"), "Value": _lc_text(tag_el, "Value")}
+ f_gt = _lc_text(filt_el, "ObjectSizeGreaterThan")
+ if f_gt:
+ filt["ObjectSizeGreaterThan"] = int(f_gt)
+ f_lt = _lc_text(filt_el, "ObjectSizeLessThan")
+ if f_lt:
+ filt["ObjectSizeLessThan"] = int(f_lt)
and_el = _lc_find(filt_el, "And")
if and_el is not None:
and_data: dict = {}
@@ -1412,6 +1428,12 @@ def _put_bucket_lifecycle(name: str, body: bytes):
tags.append({"Key": _lc_text(t, "Key"), "Value": _lc_text(t, "Value")})
if tags:
and_data["Tags"] = tags
+ gt = _lc_text(and_el, "ObjectSizeGreaterThan")
+ if gt:
+ and_data["ObjectSizeGreaterThan"] = int(gt)
+ lt = _lc_text(and_el, "ObjectSizeLessThan")
+ if lt:
+ and_data["ObjectSizeLessThan"] = int(lt)
filt["And"] = and_data
rule["Filter"] = filt
# Transitions
diff --git a/tests/test_dynamodb.py b/tests/test_dynamodb.py
index a06e36d5..7932c69a 100644
--- a/tests/test_dynamodb.py
+++ b/tests/test_dynamodb.py
@@ -1194,6 +1194,39 @@ def test_dynamodb_scan_filter(ddb):
for item in resp["Items"]:
assert int(item["n"]["N"]) >= 5
+def test_dynamodb_scan_projection_expression_without_select(ddb):
+ """ProjectionExpression without Select is equivalent to
+ Select=SPECIFIC_ATTRIBUTES (AWS Scan/Query docs); it must NOT be rejected as
+ incompatible with the default ALL_ATTRIBUTES. Explicit ALL_ATTRIBUTES / COUNT
+ with a ProjectionExpression still errors with the AWS message."""
+ ddb.create_table(
+ TableName="t_pe_no_select",
+ KeySchema=[{"AttributeName": "pk", "KeyType": "HASH"}],
+ AttributeDefinitions=[{"AttributeName": "pk", "AttributeType": "S"}],
+ BillingMode="PAY_PER_REQUEST",
+ )
+ ddb.put_item(TableName="t_pe_no_select", Item={"pk": {"S": "a"}, "keep": {"S": "y"}, "drop": {"S": "n"}})
+
+ # Scan: projection applied, no Select -> succeeds, only projected attr returned.
+ resp = ddb.scan(TableName="t_pe_no_select", ProjectionExpression="pk")
+ assert resp["Count"] == 1
+ assert resp["Items"][0] == {"pk": {"S": "a"}}
+
+ # Query: same rule.
+ q = ddb.query(
+ TableName="t_pe_no_select",
+ KeyConditionExpression="pk = :k",
+ ProjectionExpression="pk",
+ ExpressionAttributeValues={":k": {"S": "a"}},
+ )
+ assert q["Items"][0] == {"pk": {"S": "a"}}
+
+ # Explicit ALL_ATTRIBUTES + ProjectionExpression still rejected, exact AWS message.
+ with pytest.raises(ClientError) as exc:
+ ddb.scan(TableName="t_pe_no_select", ProjectionExpression="pk", Select="ALL_ATTRIBUTES")
+ assert exc.value.response["Error"]["Code"] == "ValidationException"
+ assert "Select value ALL_ATTRIBUTES is not compatible with ProjectionExpression" in exc.value.response["Error"]["Message"]
+
def test_dynamodb_batch_write(ddb):
ddb.create_table(
TableName="t_bw",
diff --git a/tests/test_lambda.py b/tests/test_lambda.py
index 18eb1fbc..61724171 100644
--- a/tests/test_lambda.py
+++ b/tests/test_lambda.py
@@ -2561,6 +2561,27 @@ def test_lambda_function_concurrency(lam):
resp2 = lam.get_function_concurrency(FunctionName="qa-lam-concurrency")
assert resp2.get("ReservedConcurrentExecutions") is None
+
+def test_lambda_function_recursion_config(lam):
+ """PutFunctionRecursionConfig / GetFunctionRecursionConfig round-trip; the
+ default is Terminate and a missing function is a ResourceNotFoundException."""
+ code = _zip_lambda("def handler(e,c): return {}")
+ lam.create_function(
+ FunctionName="qa-lam-recursion",
+ Runtime="python3.12",
+ Role="arn:aws:iam::000000000000:role/r",
+ Handler="index.handler",
+ Code={"ZipFile": code},
+ )
+ assert lam.get_function_recursion_config(FunctionName="qa-lam-recursion")["RecursiveLoop"] == "Terminate"
+ assert lam.put_function_recursion_config(
+ FunctionName="qa-lam-recursion", RecursiveLoop="Allow"
+ )["RecursiveLoop"] == "Allow"
+ assert lam.get_function_recursion_config(FunctionName="qa-lam-recursion")["RecursiveLoop"] == "Allow"
+ with pytest.raises(ClientError) as exc:
+ lam.get_function_recursion_config(FunctionName="does-not-exist")
+ assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
+
def test_lambda_add_remove_permission(lam):
"""AddPermission / RemovePermission / GetPolicy."""
code = _zip_lambda("def handler(e,c): return {}")
diff --git a/tests/test_s3.py b/tests/test_s3.py
index e6f5df76..c2f32914 100644
--- a/tests/test_s3.py
+++ b/tests/test_s3.py
@@ -3358,6 +3358,81 @@ def test_s3_lifecycle_abort_multipart(s3):
assert resp["Rules"][0]["AbortIncompleteMultipartUpload"]["DaysAfterInitiation"] == 7
+def test_s3_lifecycle_and_filter_echoes_object_size(s3):
+ """An And operator must echo ObjectSizeGreaterThan (default 0), and a
+ prefixless And must echo an empty Prefix. Real AWS injects both, and the
+ Terraform aws provider's GetBucketLifecycleConfiguration equality waiter
+ (reflect.DeepEqual against the expanded config, which carries
+ ObjectSizeGreaterThan=0 / Prefix="") never converges without them."""
+ bucket = "intg-s3-lc-and-size"
+ s3.create_bucket(Bucket=bucket)
+ s3.put_bucket_lifecycle_configuration(
+ Bucket=bucket,
+ LifecycleConfiguration={
+ "Rules": [{
+ "ID": "prefix-tags",
+ "Status": "Enabled",
+ "Filter": {"And": {"Prefix": "logs/", "Tags": [{"Key": "tier", "Value": "ARCHIVE"}]}},
+ "Expiration": {"Days": 90},
+ }]
+ },
+ )
+ and_op = s3.get_bucket_lifecycle_configuration(Bucket=bucket)["Rules"][0]["Filter"]["And"]
+ assert and_op["Prefix"] == "logs/"
+ assert and_op["ObjectSizeGreaterThan"] == 0
+
+ # Prefixless (tags-only) And still echoes Prefix="" and ObjectSizeGreaterThan=0.
+ s3.put_bucket_lifecycle_configuration(
+ Bucket=bucket,
+ LifecycleConfiguration={
+ "Rules": [{
+ "ID": "tags-only",
+ "Status": "Enabled",
+ "Filter": {"And": {"Tags": [{"Key": "a", "Value": "1"}, {"Key": "b", "Value": "2"}]}},
+ "Expiration": {"Days": 10},
+ }]
+ },
+ )
+ and_op = s3.get_bucket_lifecycle_configuration(Bucket=bucket)["Rules"][0]["Filter"]["And"]
+ assert and_op["Prefix"] == ""
+ assert and_op["ObjectSizeGreaterThan"] == 0
+
+
+def test_s3_lifecycle_object_size_round_trip(s3):
+ """Explicit object-size filters round-trip, both inside an And and at the
+ top level of a Filter (previously the parser dropped them)."""
+ bucket = "intg-s3-lc-size-rt"
+ s3.create_bucket(Bucket=bucket)
+ s3.put_bucket_lifecycle_configuration(
+ Bucket=bucket,
+ LifecycleConfiguration={
+ "Rules": [{
+ "ID": "and-sizes",
+ "Status": "Enabled",
+ "Filter": {"And": {"Prefix": "p/", "ObjectSizeGreaterThan": 100, "ObjectSizeLessThan": 200}},
+ "Expiration": {"Days": 20},
+ }]
+ },
+ )
+ and_op = s3.get_bucket_lifecycle_configuration(Bucket=bucket)["Rules"][0]["Filter"]["And"]
+ assert and_op["ObjectSizeGreaterThan"] == 100
+ assert and_op["ObjectSizeLessThan"] == 200
+
+ s3.put_bucket_lifecycle_configuration(
+ Bucket=bucket,
+ LifecycleConfiguration={
+ "Rules": [{
+ "ID": "filter-gt",
+ "Status": "Enabled",
+ "Filter": {"ObjectSizeGreaterThan": 500},
+ "Expiration": {"Days": 30},
+ }]
+ },
+ )
+ filt = s3.get_bucket_lifecycle_configuration(Bucket=bucket)["Rules"][0]["Filter"]
+ assert filt["ObjectSizeGreaterThan"] == 500
+
+
# ============================================================================
# Object ACL (GetObjectAcl / PutObjectAcl)
# ============================================================================