Skip to content

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

fix-eks-ot (#754)

Nahuel Nucera04f02b8f952d
diff --git a/ministack/services/apigateway_v1.py b/ministack/services/apigateway_v1.py
index b08ee7ca..6b0a0852 100644
--- a/ministack/services/apigateway_v1.py
+++ b/ministack/services/apigateway_v1.py
@@ -978,12 +978,22 @@ async def _invoke_lambda_proxy_v1(integration, api_id, stage_name, stage, resour
resp_headers = {"Content-Type": "application/json"}
resp_headers.update(lambda_response.get("headers", {}))
# Payload format 1.0 carries multi-value headers (notably Set-Cookie) in
- # `multiValueHeaders`. AWS merges these over `headers`, with multiValueHeaders
- # winning on key collision. Each list value is expanded into one header line
- # per entry by _send_response.
+ # `multiValueHeaders`. AWS docs: "If you specify values for both `headers`
+ # and `multiValueHeaders`, API Gateway merges them into a single list. If
+ # the same key-value pair is specified in both, only the values from
+ # `multiValueHeaders` will appear in the merged list." HTTP headers are
+ # case-insensitive (RFC 7230 §3.2), so the collision check must compare
+ # case-folded — `Set-Cookie` in `headers` plus `set-cookie` in
+ # `multiValueHeaders` is the SAME header. Each list value is then expanded
+ # into one header line per entry by _send_response.
for k, v in (lambda_response.get("multiValueHeaders") or {}).items():
- if v:
- resp_headers[k] = list(v)
+ if not v:
+ continue
+ lower_k = k.lower()
+ for existing in list(resp_headers):
+ if existing.lower() == lower_k:
+ del resp_headers[existing]
+ resp_headers[k] = list(v)
resp_body = lambda_response.get("body", "")
if isinstance(resp_body, str):
resp_body = resp_body.encode("utf-8")
diff --git a/ministack/services/dynamodb.py b/ministack/services/dynamodb.py
index 23e9c4de..0719f409 100644
--- a/ministack/services/dynamodb.py
+++ b/ministack/services/dynamodb.py
@@ -263,7 +263,7 @@ def _validate_attribute_value(attr_name: str, value: dict) -> tuple | None:
elif vtype == "NULL":
if vval is not True:
return error_response_json("ValidationException",
- "One or more parameter values were invalid: NULL attribute value must be true.", 400)
+ "One or more parameter values were invalid: Null attribute value types must have the value of true", 400)
elif vtype == "SS":
if not isinstance(vval, list) or not vval:
return error_response_json("ValidationException",
@@ -691,16 +691,20 @@ def _validate_data_plane_table_name(name) -> tuple | None:
"""Used by PutItem/GetItem/DeleteItem/UpdateItem/Query/Scan: returns a
ValidationException for null, empty, too-long, or pattern-violating
table names — BEFORE any other validators fire so the conformance
- 'reports only tableName' tests match."""
+ 'reports only tableName' tests match. Data-plane length range is 1..255
+ (the 3-char minimum is a control-plane rule)."""
if name is None:
return error_response_json("ValidationException",
"1 validation error detected: Value null at 'tableName' failed to satisfy constraint: Member must not be null", 400)
if not isinstance(name, str):
return error_response_json("ValidationException",
"1 validation error detected: Value at 'tableName' failed to satisfy constraint: Member must be a string", 400)
- if len(name) < 3 or len(name) > 255:
+ if len(name) < 1:
return error_response_json("ValidationException",
- f"1 validation error detected: Value '{name}' at 'tableName' failed to satisfy constraint: Member must have length between 3 and 255", 400)
+ f"1 validation error detected: Value '{name}' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 1", 400)
+ if len(name) > 255:
+ return error_response_json("ValidationException",
+ f"1 validation error detected: Value '{name}' at 'tableName' failed to satisfy constraint: Member must have length less than or equal to 255", 400)
if not re.match(r"^[A-Za-z0-9_.\-]+$", name):
return error_response_json("ValidationException",
f"1 validation error detected: Value '{name}' at 'tableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+", 400)
@@ -749,13 +753,18 @@ _VALID_PROJECTION_TYPES = {"ALL", "KEYS_ONLY", "INCLUDE"}
def _validate_table_name(name: str) -> tuple | None:
- """Per AWS DynamoDB Developer Guide: 3-255 chars, pattern [A-Za-z0-9_.-]."""
+ """Per AWS DynamoDB Developer Guide: 3-255 chars, pattern [A-Za-z0-9_.-].
+ Used by CreateTable; data-plane uses a wider 1..255 range via
+ `_validate_data_plane_table_name`."""
if not isinstance(name, str) or not name:
return error_response_json("ValidationException",
"1 validation error detected: Value null at 'tableName' failed to satisfy constraint: Member must not be null", 400)
- if len(name) < 3 or len(name) > 255:
+ if len(name) < 3:
+ return error_response_json("ValidationException",
+ f"1 validation error detected: Value '{name}' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 3", 400)
+ if len(name) > 255:
return error_response_json("ValidationException",
- f"1 validation error detected: Value '{name}' at 'tableName' failed to satisfy constraint: Member must have length between 3 and 255", 400)
+ f"1 validation error detected: Value '{name}' at 'tableName' failed to satisfy constraint: Member must have length less than or equal to 255", 400)
if not _TABLE_NAME_RE.match(name):
return error_response_json("ValidationException",
f"1 validation error detected: Value '{name}' at 'tableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+", 400)
@@ -778,7 +787,7 @@ def _validate_key_schema(key_schema: list, attr_defs: list, context: str = "tabl
hash_count = 0
range_count = 0
seen_names = set()
- for ks in key_schema:
+ for idx, ks in enumerate(key_schema, start=1):
attr = ks.get("AttributeName")
kt = ks.get("KeyType")
if not attr:
@@ -786,11 +795,10 @@ def _validate_key_schema(key_schema: list, attr_defs: list, context: str = "tabl
"1 validation error detected: Value null at 'keySchema.member.attributeName' failed to satisfy constraint: Member must not be null", 400)
if kt not in _VALID_KEY_TYPES:
return error_response_json("ValidationException",
- f"1 validation error detected: Value '{kt}' at 'keySchema.{len(seen_names)+1}.member.keyType' failed to satisfy constraint: Member must satisfy enum value set: [HASH, RANGE]", 400)
+ f"1 validation error detected: Value '{kt}' at 'keySchema.{idx}.member.keyType' failed to satisfy constraint: Member must satisfy enum value set: [HASH, RANGE]", 400)
if attr in seen_names:
- # AWS-canonical: duplicate-attribute-in-KeySchema rejection.
return error_response_json("ValidationException",
- f"Invalid KeySchema: Some index key attributes are repeated. RepeatedKeyElement: {attr}", 400)
+ "Invalid KeySchema: Some index key attribute have no definition", 400)
seen_names.add(attr)
if kt == "HASH":
hash_count += 1
@@ -813,6 +821,11 @@ def _validate_key_schema(key_schema: list, attr_defs: list, context: str = "tabl
def _create_table(data):
+ # AWS distinguishes absent-TableName (parameter required) from null/empty
+ # TableName (length / pattern violations). Match both message classes.
+ if "TableName" not in data:
+ return error_response_json("ValidationException",
+ "The parameter 'TableName' is required but was not present in the request", 400)
name = data.get("TableName")
err = _validate_table_name(name)
if err:
@@ -824,7 +837,7 @@ def _create_table(data):
attr_defs = data.get("AttributeDefinitions") or []
# Validate AttributeDefinitions structure.
seen_attr_names = set()
- for ad in attr_defs:
+ for idx, ad in enumerate(attr_defs, start=1):
an = ad.get("AttributeName")
at = ad.get("AttributeType")
if not an:
@@ -832,7 +845,7 @@ def _create_table(data):
"1 validation error detected: AttributeDefinitions element missing AttributeName", 400)
if at not in _VALID_ATTR_TYPES:
return error_response_json("ValidationException",
- f"1 validation error detected: Value '{at}' at 'attributeDefinitions..attributeType' failed to satisfy constraint: Member must satisfy enum value set: [B, N, S]", 400)
+ f"1 validation error detected: Value '{at}' at 'attributeDefinitions.{idx}.member.attributeType' failed to satisfy constraint: Member must satisfy enum value set: [B, N, S]", 400)
if an in seen_attr_names:
return error_response_json("ValidationException",
f"Duplicate AttributeName in AttributeDefinitions: {an}", 400)
@@ -1228,7 +1241,7 @@ def _validate_expression_attrs(data, expression_fields: tuple) -> tuple | None:
for ref in re.findall(r"#[A-Za-z_][A-Za-z0-9_]*", body):
if not ean or ref not in ean:
return error_response_json("ValidationException",
- f"Invalid {fname}: An expression attribute name used in expression is not defined; attribute name: {ref}", 400)
+ f"Invalid {fname}: An expression attribute name used in the document path is not defined; attribute name: {ref}", 400)
return None
@@ -1469,7 +1482,7 @@ def _update_item(data):
# An empty UpdateExpression string is rejected by AWS.
if "UpdateExpression" in data and not update_expr.strip():
return error_response_json("ValidationException",
- "Invalid UpdateExpression: The expression cannot be empty;", 400)
+ "Invalid UpdateExpression: The expression can not be empty;", 400)
if update_expr:
try:
@@ -1564,11 +1577,11 @@ def _query(data):
if "KeyConditionExpression" in data and not (data["KeyConditionExpression"] or "").strip():
# AWS-canonical (dynamodb-conformance.org capture).
return error_response_json("ValidationException",
- "Invalid KeyConditionExpression: The expression cannot be empty;", 400)
+ "Invalid KeyConditionExpression: The expression can not be empty;", 400)
# Select must be one of the canonical enum values when supplied.
if "Select" in data and data["Select"] not in {"ALL_ATTRIBUTES", "ALL_PROJECTED_ATTRIBUTES", "SPECIFIC_ATTRIBUTES", "COUNT"}:
return error_response_json("ValidationException",
- f"1 validation error detected: Value '{data['Select']}' at 'select' failed to satisfy constraint: Member must satisfy enum value set: [ALL_ATTRIBUTES, ALL_PROJECTED_ATTRIBUTES, SPECIFIC_ATTRIBUTES, COUNT]", 400)
+ f"1 validation error detected: Value '{data['Select']}' at 'select' failed to satisfy constraint: Member must satisfy enum value set: [SPECIFIC_ATTRIBUTES, COUNT, ALL_ATTRIBUTES, ALL_PROJECTED_ATTRIBUTES]", 400)
# Malformed ExclusiveStartKey: must include all key attributes of the
# table (and the index, if querying an index).
esk_val = data.get("ExclusiveStartKey")
@@ -1578,7 +1591,7 @@ def _query(data):
# Limit must be >= 1 when supplied.
if limit is not None and int(limit) <= 0:
return error_response_json("ValidationException",
- f"1 validation error detected: Value at 'limit' failed to satisfy constraint: Member must have value greater than or equal to 1", 400)
+ f"1 validation error detected: Value at 'Limit' failed to satisfy constraint: Member must have value greater than or equal to 1", 400)
# Select validation per AWS: ALL_PROJECTED_ATTRIBUTES is only valid on an
# index; SPECIFIC_ATTRIBUTES requires a ProjectionExpression / AttributesToGet.
if select == "ALL_PROJECTED_ATTRIBUTES" and not index_name:
@@ -1594,6 +1607,22 @@ def _query(data):
return error_response_json("ValidationException",
f"Consistent reads are not supported on global secondary indexes", 400)
+ # ExclusiveStartKey must contain the base table's key attributes; when
+ # querying an index, it must also contain the index's key attributes.
+ # Real DynamoDB's LastEvaluatedKey always carries both sets, so a missing
+ # attribute means the cursor wasn't issued by a previous Query response.
+ if esk:
+ required = {table["pk_name"]}
+ if table.get("sk_name"):
+ required.add(table["sk_name"])
+ if index_name:
+ required.add(pk_name)
+ if sk_name:
+ required.add(sk_name)
+ if not required.issubset(esk.keys()):
+ return error_response_json("ValidationException",
+ "The provided starting key is invalid", 400)
+
if key_conditions:
pk_val = _extract_pk_from_key_conditions(key_conditions, pk_name)
else:
@@ -1654,7 +1683,7 @@ def _query(data):
candidates = [it for it in candidates if _evaluate_key_conditions_item(it, key_conditions, pk_name)]
elif key_cond:
try:
- candidates = [it for it in candidates if _evaluate_condition(key_cond, it, eav, ean)]
+ candidates = [it for it in candidates if _evaluate_condition(key_cond, it, eav, ean, slot="KeyConditionExpression")]
except ValueError as exc:
return error_response_json("ValidationException", str(exc), 400)
@@ -1671,7 +1700,10 @@ def _query(data):
if query_filter and not filter_expr:
filtered = [it for it in candidates if _evaluate_legacy_filter(it, query_filter)]
elif filter_expr:
- filtered = [it for it in candidates if _evaluate_condition(filter_expr, it, eav, ean)]
+ try:
+ filtered = [it for it in candidates if _evaluate_condition(filter_expr, it, eav, ean, slot="FilterExpression")]
+ except ValueError as exc:
+ return error_response_json("ValidationException", str(exc), 400)
else:
filtered = candidates
@@ -1752,20 +1784,18 @@ def _scan(data):
total_segments = data.get("TotalSegments")
if segment is not None and total_segments is None:
return error_response_json("ValidationException",
- "The TotalSegments parameter is required when Segment is provided", 400)
+ "The TotalSegments parameter is required but was not present in the request when Segment parameter is present", 400)
if total_segments is not None and segment is None:
- # AWS-canonical (dynamodb-conformance.org capture).
return error_response_json("ValidationException",
- "The Segment parameter is required but no value was provided.", 400)
+ "The Segment parameter is required but was not present in the request when parameter TotalSegments is present", 400)
if segment is not None and total_segments is not None:
seg = int(segment); ts = int(total_segments)
if ts < 1 or ts > 1_000_000:
return error_response_json("ValidationException",
f"TotalSegments must be between 1 and 1000000", 400)
if seg < 0 or seg >= ts:
- # AWS-canonical.
return error_response_json("ValidationException",
- "The Segment parameter is zero-based and must be less than parameter TotalSegments.", 400)
+ f"The Segment parameter is zero-based and must be less than parameter TotalSegments: Segment: {seg} is not less than TotalSegments: {ts}", 400)
# Select validation.
if select == "ALL_PROJECTED_ATTRIBUTES" and not index_name:
return error_response_json("ValidationException",
@@ -1814,6 +1844,19 @@ def _scan(data):
all_items = [it for it in all_items if _seg_match(it)]
if esk:
+ # ESK must contain the base-table key attributes (and the index's keys
+ # when scanning an index). AWS LastEvaluatedKey always carries both sets;
+ # a missing attribute indicates the cursor wasn't issued by Scan.
+ required = {table["pk_name"]}
+ if table.get("sk_name"):
+ required.add(table["sk_name"])
+ if index_name:
+ required.add(pk_name_idx)
+ if sk_name_idx:
+ required.add(sk_name_idx)
+ if not required.issubset(esk.keys()):
+ return error_response_json("ValidationException",
+ "The provided starting key is invalid: The provided key element does not match the schema", 400)
all_items = _apply_exclusive_start_key_scan(all_items, esk, table)
has_more = False
@@ -1829,7 +1872,7 @@ def _scan(data):
filtered = [it for it in all_items if _evaluate_legacy_filter(it, scan_filter)]
elif filter_expr:
try:
- filtered = [it for it in all_items if _evaluate_condition(filter_expr, it, eav, ean)]
+ filtered = [it for it in all_items if _evaluate_condition(filter_expr, it, eav, ean, slot="FilterExpression")]
except ValueError as exc:
return error_response_json("ValidationException", str(exc), 400)
else:
@@ -2397,9 +2440,8 @@ def _split_top_level(s, delimiter):
def _batch_write_item(data):
request_items = data.get("RequestItems")
if not request_items:
- # AWS-captured exact message (dynamodb-conformance.org suite).
return error_response_json("ValidationException",
- "The requestItems parameter is required.", 400)
+ "The requestItems parameter is required for BatchWriteItem", 400)
# Total request count cap (25 per BatchWriteItem call).
total = sum(len(v) for v in request_items.values())
if total > _DDB_BATCH_WRITE_MAX:
@@ -2485,14 +2527,14 @@ def _batch_write_item(data):
def _batch_get_item(data):
request_items = data.get("RequestItems")
if not request_items:
- # AWS-captured exact message (dynamodb-conformance.org suite).
return error_response_json("ValidationException",
- "The requestItems parameter is required.", 400)
- # Total key count cap (100 per BatchGetItem call).
- total = sum(len(cfg.get("Keys", [])) for cfg in request_items.values())
- if total > _DDB_BATCH_GET_MAX:
- return error_response_json("ValidationException",
- f"1 validation error detected: Value at 'requestItems' failed to satisfy constraint: Member must have length less than or equal to {_DDB_BATCH_GET_MAX}", 400)
+ "The requestItems parameter is required for BatchGetItem", 400)
+ # Per-table key cap (100 per BatchGetItem call, per-table path in the error).
+ for _bg_table_name, _bg_cfg in request_items.items():
+ _bg_keys = _bg_cfg.get("Keys", [])
+ if len(_bg_keys) > _DDB_BATCH_GET_MAX:
+ return error_response_json("ValidationException",
+ f"1 validation error detected: Value at 'RequestItems.{_bg_table_name}.member.Keys' failed to satisfy constraint: Member must have length less than or equal to {_DDB_BATCH_GET_MAX}", 400)
# Non-existent table check before processing (AWS validates upfront).
for table_name in request_items:
if table_name not in _tables:
@@ -2943,7 +2985,7 @@ def _validate_kinesis_destination_request(data: dict) -> tuple[str | None, str |
table_name = data.get("TableName")
stream_arn = data.get("StreamArn")
if not table_name:
- return None, None, error_response_json("ValidationException", "TableName is required", 400)
+ return None, None, error_response_json("ValidationException", "The parameter 'TableName' is required but was not present in the request", 400)
if table_name not in _tables:
return None, None, error_response_json(
"ResourceNotFoundException", f"Table not found: {table_name}", 400
@@ -3053,7 +3095,7 @@ def _disable_kinesis_streaming_destination(data):
def _describe_kinesis_streaming_destination(data):
table_name = data.get("TableName")
if not table_name:
- return error_response_json("ValidationException", "TableName is required", 400)
+ return error_response_json("ValidationException", "The parameter 'TableName' is required but was not present in the request", 400)
if table_name not in _tables:
return error_response_json(
"ResourceNotFoundException", f"Table not found: {table_name}", 400
@@ -4034,8 +4076,11 @@ class _ExprEval:
except Exception:
return v.encode("latin-1") if isinstance(v, str) else b""
return _b(attr["B"]).startswith(_b(substr["B"]))
- # AWS rejects begins_with on a non-string/binary operand.
- raise ValueError("Incorrect operand type for operator or function; operator or function: begins_with")
+ # AWS rejects begins_with on a non-string/binary operand. The caller's
+ # error wrapper prepends "Invalid <slot>:". Report the operand's type
+ # (first key of the AttributeValue map: N, BOOL, NULL, …).
+ op_type = next(iter(substr.keys())) if isinstance(substr, dict) and substr else "?"
+ raise ValueError(f"Incorrect operand type for operator or function; operator or function: begins_with, operand type: {op_type}")
def _fn_contains(self):
self.advance(); self.expect('LPAREN')
@@ -4102,15 +4147,16 @@ def _check_reserved_keyword_usage(tokens) -> str | None:
return None
-def _check_redundant_parens(tokens) -> str | None:
+def _check_redundant_parens(tokens, slot: str = "ConditionExpression") -> str | None:
"""AWS rejects ConditionExpression / FilterExpression / KeyConditionExpression
that contain redundant parentheses. The unambiguous, low-false-positive
detection rule: an LPAREN whose immediately-following token is another
LPAREN whose matching RPAREN is followed directly by the outer RPAREN —
i.e. the `((expr))` pattern.
- Returns the AWS-canonical error string when redundancy is detected, or
- None when the expression is fine.
+ Returns the AWS-canonical error string (`"Invalid <slot>: The expression
+ has redundant parentheses;"`) when redundancy is detected, or None when
+ the expression is fine.
"""
n = len(tokens)
for i in range(n - 1):
@@ -4127,16 +4173,21 @@ def _check_redundant_parens(tokens) -> str | None:
inner_end = j
break
if inner_end is not None and inner_end + 1 < n and tokens[inner_end + 1][0] == 'RPAREN':
- return "Invalid ConditionExpression: The expression has redundant parentheses"
+ return f"Invalid {slot}: The expression has redundant parentheses;"
return None
-def _evaluate_condition(expr, item, attr_values, attr_names):
+def _evaluate_condition(expr, item, attr_values, attr_names,
+ slot: str = "ConditionExpression"):
+ """Evaluate a DynamoDB expression. ``slot`` controls the "Invalid <X>:"
+ prefix on error strings — pass "FilterExpression" / "KeyConditionExpression"
+ / "ConditionExpression" so AWS-canonical wrapping matches the request
+ parameter the expression came from."""
if not expr or not expr.strip():
return True
try:
tokens = _tokenize(expr)
- err = _check_redundant_parens(tokens)
+ err = _check_redundant_parens(tokens, slot)
if err:
raise ValueError(err)
err = _check_reserved_keyword_usage(tokens)
@@ -4145,9 +4196,7 @@ def _evaluate_condition(expr, item, attr_values, attr_names):
return _ExprEval(tokens, item, attr_values, attr_names).evaluate()
except ValueError as e:
msg = str(e)
- # If the inner error is already an AWS-canonical message
- # (e.g. "Invalid ConditionExpression: ..." or "Invalid UpdateExpression: ..."),
- # propagate it verbatim. Otherwise wrap in the generic prefix.
+ # If the inner error is already an AWS-canonical message, propagate.
if msg.startswith("Invalid ConditionExpression:") \
or msg.startswith("Invalid UpdateExpression:") \
or msg.startswith("Invalid FilterExpression:") \
@@ -4155,10 +4204,10 @@ def _evaluate_condition(expr, item, attr_values, attr_names):
or msg.startswith("Invalid ProjectionExpression:"):
raise
logger.warning("Expression evaluation error: %s for expr: %s", e, expr)
- raise ValueError(f"Invalid ConditionExpression: {e}")
+ raise ValueError(f"Invalid {slot}: {e}")
except Exception as e:
logger.warning("Expression evaluation error: %s for expr: %s", e, expr)
- raise ValueError(f"Invalid ConditionExpression: {e}")
+ raise ValueError(f"Invalid {slot}: {e}")
# ---------------------------------------------------------------------------
diff --git a/ministack/services/ec2.py b/ministack/services/ec2.py
index 921b1d89..149f4f5d 100644
--- a/ministack/services/ec2.py
+++ b/ministack/services/ec2.py
@@ -4395,19 +4395,28 @@ def _lt_data_xml(data):
return xml
-def _lt_version_xml(ver):
- """Render a single launch template version as XML."""
- xml = f"""<item>
- <launchTemplateId>{_esc(ver['LaunchTemplateId'])}</launchTemplateId>
+def _lt_version_inner_xml(ver):
+ """Render the inner fields of a launch template version (no wrapper).
+
+ AWS uses two response shapes for the same struct: a SINGLE
+ `<launchTemplateVersion>{fields}</launchTemplateVersion>` for
+ CreateLaunchTemplateVersion, and a LIST
+ `<launchTemplateVersionSet><item>{fields}</item>...</launchTemplateVersionSet>`
+ for DescribeLaunchTemplateVersions. The `<item>` wrapper belongs at the
+ list-context boundary, not on the inner struct."""
+ return f"""<launchTemplateId>{_esc(ver['LaunchTemplateId'])}</launchTemplateId>
<launchTemplateName>{_esc(ver['LaunchTemplateName'])}</launchTemplateName>
<versionNumber>{ver['VersionNumber']}</versionNumber>
<versionDescription>{_esc(ver.get('VersionDescription', ''))}</versionDescription>
<defaultVersion>{str(ver.get('DefaultVersion', False)).lower()}</defaultVersion>
<createTime>{ver['CreateTime']}</createTime>
<createdBy>arn:aws:iam::{get_account_id()}:root</createdBy>
- <launchTemplateData>{_lt_data_xml(ver.get('LaunchTemplateData', {}))}</launchTemplateData>
- </item>"""
- return xml
+ <launchTemplateData>{_lt_data_xml(ver.get('LaunchTemplateData', {}))}</launchTemplateData>"""
+
+
+def _lt_version_xml(ver):
+ """List-context wrapper used by DescribeLaunchTemplateVersions."""
+ return f"<item>{_lt_version_inner_xml(ver)}</item>"
def _create_launch_template(p):
@@ -4516,7 +4525,7 @@ def _create_launch_template_version(p):
lt["Versions"].append(version)
lt["LatestVersionNumber"] = ver_num
return _xml(200, "CreateLaunchTemplateVersionResponse",
- f"<launchTemplateVersion>{_lt_version_xml(version)}</launchTemplateVersion>")
+ f"<launchTemplateVersion>{_lt_version_inner_xml(version)}</launchTemplateVersion>")
def _describe_launch_templates(p):
diff --git a/ministack/services/eks.py b/ministack/services/eks.py
index b557d293..c788399d 100644
--- a/ministack/services/eks.py
+++ b/ministack/services/eks.py
@@ -52,6 +52,7 @@ except ImportError:
_clusters = AccountScopedDict() # name -> cluster record
_nodegroups = AccountScopedDict() # "cluster/nodegroup" -> nodegroup record
+_addons = AccountScopedDict() # "cluster/addonName" -> addon record
_tags = AccountScopedDict() # arn -> {key: value}
_port_counter_lock = threading.Lock()
_port_counter = [EKS_BASE_PORT]
@@ -60,6 +61,7 @@ _port_counter = [EKS_BASE_PORT]
def reset():
_clusters.clear()
_nodegroups.clear()
+ _addons.clear()
_tags.clear()
_port_counter[0] = EKS_BASE_PORT
_stop_all_k3s()
@@ -77,6 +79,7 @@ def get_state():
return {
"clusters": clusters,
"nodegroups": copy.deepcopy(_nodegroups),
+ "addons": copy.deepcopy(_addons),
"tags": copy.deepcopy(_tags),
"port_counter": _port_counter[0],
}
@@ -85,6 +88,7 @@ def get_state():
def restore_state(data):
_clusters.update(data.get("clusters", {}))
_nodegroups.update(data.get("nodegroups", {}))
+ _addons.update(data.get("addons", {}))
_tags.update(data.get("tags", {}))
if "port_counter" in data:
_port_counter[0] = data["port_counter"]
@@ -125,6 +129,11 @@ def _nodegroup_arn(cluster_name, ng_name):
return f"arn:aws:eks:{get_region()}:{get_account_id()}:nodegroup/{cluster_name}/{ng_name}/{new_uuid()[:8]}"
+def _addon_arn(cluster_name, addon_name):
+ # AWS uses arn:aws:eks:{region}:{account}:addon/{cluster}/{addonName}/{uuid}.
+ return f"arn:aws:eks:{get_region()}:{get_account_id()}:addon/{cluster_name}/{addon_name}/{new_uuid()[:8]}"
+
+
def _now():
return int(time.time())
@@ -481,6 +490,103 @@ def _delete_nodegroup(cluster_name, ng_name):
return _json_resp(200, {"nodegroup": result})
+# ---------------------------------------------------------------------------
+# Addons
+# ---------------------------------------------------------------------------
+# CreateAddon / DescribeAddon / DeleteAddon / ListAddons / UpdateAddon.
+# Status flips ACTIVE on Create / Update (same shortcut as nodegroups —
+# Terraform polls until ACTIVE so a slow-roll status would only stall tests).
+# Delete returns the record with status=DELETING and drops the entry.
+
+def _create_addon(cluster_name, body):
+ if cluster_name not in _clusters:
+ return _error(404, "ResourceNotFoundException",
+ f"No cluster found for name: {cluster_name}.")
+ addon_name = body.get("addonName", "")
+ if not addon_name:
+ return _error(400, "InvalidParameterException", "Addon name is required.")
+
+ key = f"{cluster_name}/{addon_name}"
+ if key in _addons:
+ return _error(409, "ResourceInUseException",
+ f"Addon already exists with name: {addon_name}")
+
+ arn = _addon_arn(cluster_name, addon_name)
+ now = _now()
+ addon = {
+ "addonName": addon_name,
+ "clusterName": cluster_name,
+ "status": "ACTIVE",
+ "addonVersion": body.get("addonVersion", ""),
+ "addonArn": arn,
+ "createdAt": now,
+ "modifiedAt": now,
+ "serviceAccountRoleArn": body.get("serviceAccountRoleArn", ""),
+ "tags": body.get("tags", {}),
+ "configurationValues": body.get("configurationValues", ""),
+ "podIdentityAssociations": body.get("podIdentityAssociations", []),
+ "health": {"issues": []},
+ "owner": "aws",
+ "publisher": "eks",
+ }
+ _addons[key] = addon
+ if addon["tags"]:
+ _tags[arn] = dict(addon["tags"])
+ return _json_resp(200, {"addon": addon})
+
+
+def _describe_addon(cluster_name, addon_name):
+ addon = _addons.get(f"{cluster_name}/{addon_name}")
+ if not addon:
+ return _error(404, "ResourceNotFoundException",
+ f"No addon found for cluster {cluster_name} addon {addon_name}")
+ return _json_resp(200, {"addon": addon})
+
+
+def _list_addons(cluster_name, query):
+ if cluster_name not in _clusters:
+ return _error(404, "ResourceNotFoundException",
+ f"No cluster found for name: {cluster_name}.")
+ max_results = int(query.get("maxResults", 100))
+ names = [a["addonName"] for k, a in _addons.items()
+ if k.startswith(f"{cluster_name}/")][:max_results]
+ return _json_resp(200, {"addons": names})
+
+
+def _delete_addon(cluster_name, addon_name):
+ key = f"{cluster_name}/{addon_name}"
+ addon = _addons.get(key)
+ if not addon:
+ return _error(404, "ResourceNotFoundException",
+ f"No addon found for cluster {cluster_name} addon {addon_name}")
+ addon["status"] = "DELETING"
+ result = dict(addon)
+ _addons.pop(key, None)
+ _tags.pop(addon.get("addonArn", ""), None)
+ return _json_resp(200, {"addon": result})
+
+
+def _update_addon(cluster_name, addon_name, body):
+ key = f"{cluster_name}/{addon_name}"
+ addon = _addons.get(key)
+ if not addon:
+ return _error(404, "ResourceNotFoundException",
+ f"No addon found for cluster {cluster_name} addon {addon_name}")
+ for field in ("addonVersion", "serviceAccountRoleArn",
+ "configurationValues", "podIdentityAssociations"):
+ if field in body:
+ addon[field] = body[field]
+ addon["modifiedAt"] = _now()
+ addon["status"] = "ACTIVE"
+ update = {
+ "id": new_uuid(),
+ "status": "Successful",
+ "type": "AddonUpdate",
+ "createdAt": _now(),
+ }
+ return _json_resp(200, {"update": update})
+
+
# ---------------------------------------------------------------------------
# Tags
# ---------------------------------------------------------------------------
@@ -566,6 +672,33 @@ async def handle_request(method, path, headers, body_bytes, query_params):
if method == "DELETE":
return _delete_nodegroup(cluster_name, ng_name)
+ # POST/GET /clusters/{name}/addons
+ m = re.fullmatch(r"/clusters/([A-Za-z0-9_-]+)/addons", path)
+ if m:
+ cluster_name = m.group(1)
+ if method == "POST":
+ return _create_addon(cluster_name, body)
+ if method == "GET":
+ return _list_addons(cluster_name, query)
+
+ # POST /clusters/{name}/addons/{addonName}/update — UpdateAddon.
+ # Must come BEFORE the generic /addons/{addonName} pattern so the
+ # `/update` suffix isn't swallowed by the wider regex.
+ m = re.fullmatch(r"/clusters/([A-Za-z0-9_-]+)/addons/([A-Za-z0-9_.-]+)/update", path)
+ if m:
+ cluster_name, addon_name = m.group(1), m.group(2)
+ if method == "POST":
+ return _update_addon(cluster_name, addon_name, body)
+
+ # GET/DELETE /clusters/{name}/addons/{addonName}
+ m = re.fullmatch(r"/clusters/([A-Za-z0-9_-]+)/addons/([A-Za-z0-9_.-]+)", path)
+ if m:
+ cluster_name, addon_name = m.group(1), m.group(2)
+ if method == "GET":
+ return _describe_addon(cluster_name, addon_name)
+ if method == "DELETE":
+ return _delete_addon(cluster_name, addon_name)
+
# Tags: /tags/{arn+}
if path.startswith("/tags/"):
arn = path[6:]
diff --git a/tests/test_apigatewayv1.py b/tests/test_apigatewayv1.py
index 50d0279a..a164834c 100644
--- a/tests/test_apigatewayv1.py
+++ b/tests/test_apigatewayv1.py
@@ -562,6 +562,78 @@ def test_apigwv1_execute_lambda_proxy_multi_value_headers(apigw_v1, lam):
lam.delete_function(FunctionName=fname)
+def test_apigwv1_execute_lambda_proxy_mvh_wins_case_insensitive(apigw_v1, lam):
+ """Case-insensitive collision between `headers` and `multiValueHeaders`.
+
+ Per AWS docs: "If the same key-value pair is specified in both, only the
+ values from `multiValueHeaders` will appear in the merged list." HTTP
+ headers are case-insensitive, so `Set-Cookie` in `headers` plus
+ `set-cookie` in `multiValueHeaders` must NOT both ship — only the MVH
+ values win.
+ """
+ import urllib.request as _urlreq
+ import uuid as _uuid
+
+ fname = f"intg-v1-mvh-case-{_uuid.uuid4().hex[:8]}"
+ code = (
+ b"def handler(event, context):\n"
+ b" return {\n"
+ b" 'statusCode': 200,\n"
+ b" 'headers': {'Set-Cookie': 'should-be-dropped=1; Path=/'},\n"
+ b" 'multiValueHeaders': {'set-cookie': ['a=1; Path=/', 'b=2; Path=/']},\n"
+ b" 'body': 'ok',\n"
+ b" }\n"
+ )
+ buf = io.BytesIO()
+ with zipfile.ZipFile(buf, "w") as zf:
+ zf.writestr("index.py", code)
+ lam.create_function(
+ FunctionName=fname,
+ Runtime="python3.12",
+ Role="arn:aws:iam::000000000000:role/test-role",
+ Handler="index.handler",
+ Code={"ZipFile": buf.getvalue()},
+ )
+
+ api_id = apigw_v1.create_rest_api(name=f"v1-mvh-case-{fname}")["id"]
+ root = next(r for r in apigw_v1.get_resources(restApiId=api_id)["items"] if r["path"] == "/")
+ resource_id = apigw_v1.create_resource(
+ restApiId=api_id,
+ parentId=root["id"],
+ pathPart="cookie",
+ )["id"]
+ apigw_v1.put_method(
+ restApiId=api_id,
+ resourceId=resource_id,
+ httpMethod="GET",
+ authorizationType="NONE",
+ )
+ apigw_v1.put_integration(
+ restApiId=api_id,
+ resourceId=resource_id,
+ httpMethod="GET",
+ type="AWS_PROXY",
+ integrationHttpMethod="POST",
+ uri=f"arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:000000000000:function:{fname}/invocations",
+ )
+ dep_id = apigw_v1.create_deployment(restApiId=api_id)["id"]
+ apigw_v1.create_stage(restApiId=api_id, stageName="test", deploymentId=dep_id)
+
+ url = f"http://{api_id}.execute-api.localhost:{_EXECUTE_PORT}/test/cookie"
+ req = _urlreq.Request(url, method="GET")
+ req.add_header("Host", f"{api_id}.execute-api.localhost:{_EXECUTE_PORT}")
+ resp = _urlreq.urlopen(req)
+ assert resp.status == 200
+ set_cookies = resp.headers.get_all("Set-Cookie") or []
+ # Only MVH values ship; the scalar `Set-Cookie` from `headers` is dropped.
+ assert set_cookies == ["a=1; Path=/", "b=2; Path=/"]
+ # And the scalar value is not somewhere else in the response.
+ assert all("should-be-dropped" not in c for c in set_cookies)
+
+ apigw_v1.delete_rest_api(restApiId=api_id)
+ lam.delete_function(FunctionName=fname)
+
+
@pytest.mark.skipif(not shutil.which("curl"), reason="provided bootstrap uses curl for Runtime API")
def test_apigwv1_execute_lambda_proxy_provided_runtime(apigw_v1, lam):
"""execute-api AWS_PROXY must run provided.* zips via lambda_svc (Go/terraform parity)."""
diff --git a/tests/test_dynamodb.py b/tests/test_dynamodb.py
index 43a278e4..cc9394be 100644
--- a/tests/test_dynamodb.py
+++ b/tests/test_dynamodb.py
@@ -5138,6 +5138,49 @@ def test_dynamodb_query_non_existent_index_validation(ddb):
ddb.delete_table(TableName=name)
+def test_dynamodb_query_esk_schema_mismatch_rejected(ddb):
+ """ExclusiveStartKey missing the table's key attrs must be rejected.
+
+ Mirrors nubo-db/dynamodb-conformance tier1/query/basic.test.ts —
+ expects ValidationException matching /provided starting key is invalid/.
+ """
+ name = "q-esk-schema"
+ _basic_table(ddb, name, with_sk=True)
+ try:
+ with pytest.raises(ClientError) as e:
+ ddb.query(
+ TableName=name,
+ KeyConditionExpression="pk = :pk",
+ ExpressionAttributeValues={":pk": {"S": "x"}},
+ ExclusiveStartKey={"bad": {"S": "p"}},
+ )
+ assert e.value.response["Error"]["Code"] == "ValidationException"
+ assert "provided starting key is invalid" in e.value.response["Error"]["Message"]
+ finally:
+ ddb.delete_table(TableName=name)
+
+
+def test_dynamodb_query_esk_missing_gsi_key_rejected(ddb):
+ """ExclusiveStartKey missing the GSI's key attrs on an index query must be
+ rejected. Mirrors the conformance suite case where the ESK carries only
+ base-table keys and omits the GSI hash key."""
+ name = "q-esk-gsi"
+ _gsi_table(ddb, name)
+ try:
+ with pytest.raises(ClientError) as e:
+ ddb.query(
+ TableName=name,
+ IndexName="byGsiPk",
+ KeyConditionExpression="gsi_pk = :v",
+ ExpressionAttributeValues={":v": {"S": "x"}},
+ ExclusiveStartKey={"pk": {"S": "x"}},
+ )
+ assert e.value.response["Error"]["Code"] == "ValidationException"
+ assert "provided starting key is invalid" in e.value.response["Error"]["Message"]
+ finally:
+ ddb.delete_table(TableName=name)
+
+
def test_dynamodb_scan_non_existent_index_validation(ddb):
name = "s-noidx"
_basic_table(ddb, name)
diff --git a/tests/test_ec2.py b/tests/test_ec2.py
index f10b578a..1fd5726b 100644
--- a/tests/test_ec2.py
+++ b/tests/test_ec2.py
@@ -1650,6 +1650,39 @@ def test_ec2_launch_template_versions(ec2):
ec2.delete_launch_template(LaunchTemplateId=lt_id)
+def test_ec2_create_launch_template_version_returns_version_number(ec2):
+ """CreateLaunchTemplateVersion must return VersionNumber at the
+ `launchTemplateVersion` root, not wrapped in `<item>` — otherwise the
+ Go SDK reads it as null and Terraform sends ``SetDefaultVersion=0`` to
+ the follow-up ModifyLaunchTemplate, which AWS rejects with
+ ``InvalidLaunchTemplateId.VersionNotFound``. Repro for issue #753."""
+ resp = ec2.create_launch_template(
+ LaunchTemplateName="qa-lt-vnum",
+ LaunchTemplateData={"InstanceType": "t3.micro"},
+ )
+ lt_id = resp["LaunchTemplate"]["LaunchTemplateId"]
+ try:
+ v2 = ec2.create_launch_template_version(
+ LaunchTemplateId=lt_id,
+ LaunchTemplateData={"InstanceType": "t3.small"},
+ )
+ # botocore parses the response shape; if the inner XML is wrong, this
+ # field reads as None / missing rather than the version number.
+ assert "LaunchTemplateVersion" in v2
+ v = v2["LaunchTemplateVersion"]
+ assert v.get("VersionNumber") == 2, v
+ assert v.get("LaunchTemplateId") == lt_id
+
+ # End-to-end: Terraform-style follow-up that previously failed.
+ modified = ec2.modify_launch_template(
+ LaunchTemplateId=lt_id,
+ DefaultVersion=str(v["VersionNumber"]),
+ )
+ assert modified["LaunchTemplate"]["DefaultVersionNumber"] == 2
+ finally:
+ ec2.delete_launch_template(LaunchTemplateId=lt_id)
+
+
def test_ec2_launch_template_with_block_devices(ec2):
"""Create a template with block device mappings."""
resp = ec2.create_launch_template(
diff --git a/tests/test_eks.py b/tests/test_eks.py
index 89a1dec7..6201e5b1 100644
--- a/tests/test_eks.py
+++ b/tests/test_eks.py
@@ -301,3 +301,74 @@ def test_eks_k3s_run_kwargs_container_name_and_labels():
kwargs = _k3s_run_kwargs(name="my-cluster", port=16443)
assert kwargs["name"] == "ministack-eks-my-cluster"
assert kwargs["labels"] == {"ministack": "eks", "cluster_name": "my-cluster"}
+
+
+def test_eks_addon_lifecycle(eks):
+ """CreateAddon / DescribeAddon / ListAddons / UpdateAddon / DeleteAddon.
+ Issue #752: terraform aws_eks_addon fails on missing POST /clusters/{name}/addons."""
+ import uuid as _uuid
+ cn = f"addons-{_uuid.uuid4().hex[:8]}"
+ eks.create_cluster(
+ name=cn, roleArn="arn:aws:iam::000000000000:role/eks",
+ resourcesVpcConfig={"subnetIds": ["subnet-1", "subnet-2"]},
+ )
+ try:
+ # Create the 4 standard addons in one go.
+ for name in ("vpc-cni", "coredns", "kube-proxy", "aws-ebs-csi-driver"):
+ r = eks.create_addon(clusterName=cn, addonName=name)
+ assert r["addon"]["addonName"] == name
+ assert r["addon"]["status"] == "ACTIVE"
+ assert f":addon/{cn}/{name}/" in r["addon"]["addonArn"]
+
+ # Describe one.
+ r = eks.describe_addon(clusterName=cn, addonName="coredns")
+ assert r["addon"]["status"] == "ACTIVE"
+ assert r["addon"]["addonName"] == "coredns"
+
+ # List all.
+ lst = eks.list_addons(clusterName=cn)["addons"]
+ assert set(lst) == {"vpc-cni", "coredns", "kube-proxy", "aws-ebs-csi-driver"}
+
+ # Update changes the version and surfaces a successful update record.
+ upd = eks.update_addon(
+ clusterName=cn, addonName="coredns",
+ addonVersion="v1.11.4-eksbuild.1",
+ )
+ assert upd["update"]["status"] == "Successful"
+ r = eks.describe_addon(clusterName=cn, addonName="coredns")
+ assert r["addon"]["addonVersion"] == "v1.11.4-eksbuild.1"
+
+ # Delete returns DELETING and the addon is gone afterwards.
+ d = eks.delete_addon(clusterName=cn, addonName="vpc-cni")
+ assert d["addon"]["status"] == "DELETING"
+ with pytest.raises(ClientError) as e:
+ eks.describe_addon(clusterName=cn, addonName="vpc-cni")
+ assert e.value.response["Error"]["Code"] == "ResourceNotFoundException"
+ finally:
+ try: eks.delete_cluster(name=cn)
+ except Exception: pass
+
+
+def test_eks_addon_create_on_missing_cluster_404(eks):
+ import uuid as _uuid
+ missing = f"no-such-cluster-{_uuid.uuid4().hex[:6]}"
+ with pytest.raises(ClientError) as e:
+ eks.create_addon(clusterName=missing, addonName="vpc-cni")
+ assert e.value.response["Error"]["Code"] == "ResourceNotFoundException"
+
+
+def test_eks_addon_create_duplicate_returns_resource_in_use(eks):
+ import uuid as _uuid
+ cn = f"addons-dup-{_uuid.uuid4().hex[:8]}"
+ eks.create_cluster(
+ name=cn, roleArn="arn:aws:iam::000000000000:role/eks",
+ resourcesVpcConfig={"subnetIds": ["subnet-1"]},
+ )
+ try:
+ eks.create_addon(clusterName=cn, addonName="vpc-cni")
+ with pytest.raises(ClientError) as e:
+ eks.create_addon(clusterName=cn, addonName="vpc-cni")
+ assert e.value.response["Error"]["Code"] == "ResourceInUseException"
+ finally:
+ try: eks.delete_cluster(name=cn)
+ except Exception: pass