Skip to content

Commit e548fb2

Browse files
authored
DynamoDB: Fix missing SSEDescription in UpdateTable (#11938)
1 parent 072d250 commit e548fb2

File tree

5 files changed

+87
-3
lines changed

5 files changed

+87
-3
lines changed

localstack-core/localstack/services/dynamodb/provider.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,10 @@ def update_table(
851851

852852
SchemaExtractor.invalidate_table_schema(table_name, context.account_id, global_table_region)
853853

854+
schema = SchemaExtractor.get_table_schema(
855+
table_name, context.account_id, global_table_region
856+
)
857+
854858
# TODO: DDB streams must also be created for replicas
855859
if update_table_input.get("StreamSpecification"):
856860
create_dynamodb_stream(
@@ -860,7 +864,7 @@ def update_table(
860864
result["TableDescription"].get("LatestStreamLabel"),
861865
)
862866

863-
return result
867+
return UpdateTableOutput(TableDescription=schema["Table"])
864868

865869
def list_tables(
866870
self,

localstack-core/localstack/services/dynamodb/v2/provider.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ def update_table(
614614
global_table_region = self.get_global_table_region(context, table_name)
615615

616616
try:
617-
result = self._forward_request(context=context, region=global_table_region)
617+
self._forward_request(context=context, region=global_table_region)
618618
except CommonServiceException as exc:
619619
# DynamoDBLocal refuses to update certain table params and raises.
620620
# But we still need to update this info in LocalStack stores
@@ -689,7 +689,11 @@ def update_table(
689689

690690
SchemaExtractor.invalidate_table_schema(table_name, context.account_id, global_table_region)
691691

692-
return result
692+
schema = SchemaExtractor.get_table_schema(
693+
table_name, context.account_id, global_table_region
694+
)
695+
696+
return UpdateTableOutput(TableDescription=schema["Table"])
693697

694698
def list_tables(
695699
self,

tests/aws/services/dynamodb/test_dynamodb.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,40 @@ def test_dynamodb_create_table_with_partial_sse_specification(
16531653
result = aws_client.dynamodb.describe_table(TableName=table_name)
16541654
assert "SSESpecification" not in result["Table"]
16551655

1656+
@markers.aws.validated
1657+
def test_dynamodb_update_table_without_sse_specification_change(
1658+
self, dynamodb_create_table_with_parameters, snapshot, aws_client
1659+
):
1660+
table_name = f"test_table_{short_uid()}"
1661+
1662+
sse_specification = {"Enabled": True}
1663+
1664+
result = dynamodb_create_table_with_parameters(
1665+
TableName=table_name,
1666+
KeySchema=[{"AttributeName": PARTITION_KEY, "KeyType": "HASH"}],
1667+
AttributeDefinitions=[{"AttributeName": PARTITION_KEY, "AttributeType": "S"}],
1668+
ProvisionedThroughput={"ReadCapacityUnits": 5, "WriteCapacityUnits": 5},
1669+
SSESpecification=sse_specification,
1670+
Tags=TEST_DDB_TAGS,
1671+
)
1672+
snapshot.match("SSEDescription", result["TableDescription"]["SSEDescription"])
1673+
1674+
kms_master_key_arn = result["TableDescription"]["SSEDescription"]["KMSMasterKeyArn"]
1675+
result = aws_client.kms.describe_key(KeyId=kms_master_key_arn)
1676+
snapshot.match("KMSDescription", result)
1677+
1678+
result = aws_client.dynamodb.update_table(
1679+
TableName=table_name, BillingMode="PAY_PER_REQUEST"
1680+
)
1681+
snapshot.match(
1682+
"update-table-unchanged-sse-spec", result["TableDescription"]["SSEDescription"]
1683+
)
1684+
1685+
# Verify that SSEDescription exists and remains unchanged after update_table
1686+
assert result["TableDescription"]["SSEDescription"]["Status"] == "ENABLED"
1687+
assert result["TableDescription"]["SSEDescription"]["SSEType"] == "KMS"
1688+
assert result["TableDescription"]["SSEDescription"]["KMSMasterKeyArn"] == kms_master_key_arn
1689+
16561690
@markers.aws.validated
16571691
def test_dynamodb_get_batch_items(
16581692
self, dynamodb_create_table_with_parameters, snapshot, aws_client

tests/aws/services/dynamodb/test_dynamodb.snapshot.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,5 +1417,44 @@
14171417
]
14181418
}
14191419
}
1420+
},
1421+
"tests/aws/services/dynamodb/test_dynamodb.py::TestDynamoDB::test_dynamodb_update_table_without_sse_specification_change": {
1422+
"recorded-date": "09-12-2024, 16:09:53",
1423+
"recorded-content": {
1424+
"SSEDescription": {
1425+
"KMSMasterKeyArn": "arn:<partition>:kms:<region>:111111111111:key/<uuid:1>",
1426+
"SSEType": "KMS",
1427+
"Status": "ENABLED"
1428+
},
1429+
"KMSDescription": {
1430+
"KeyMetadata": {
1431+
"AWSAccountId": "111111111111",
1432+
"Arn": "arn:<partition>:kms:<region>:111111111111:key/<uuid:1>",
1433+
"CreationDate": "datetime",
1434+
"CustomerMasterKeySpec": "SYMMETRIC_DEFAULT",
1435+
"Description": "Default key that protects my DynamoDB data when no other key is defined",
1436+
"Enabled": true,
1437+
"EncryptionAlgorithms": [
1438+
"SYMMETRIC_DEFAULT"
1439+
],
1440+
"KeyId": "<uuid:1>",
1441+
"KeyManager": "AWS",
1442+
"KeySpec": "SYMMETRIC_DEFAULT",
1443+
"KeyState": "Enabled",
1444+
"KeyUsage": "ENCRYPT_DECRYPT",
1445+
"MultiRegion": false,
1446+
"Origin": "AWS_KMS"
1447+
},
1448+
"ResponseMetadata": {
1449+
"HTTPHeaders": {},
1450+
"HTTPStatusCode": 200
1451+
}
1452+
},
1453+
"update-table-unchanged-sse-spec": {
1454+
"KMSMasterKeyArn": "arn:<partition>:kms:<region>:111111111111:key/<uuid:1>",
1455+
"SSEType": "KMS",
1456+
"Status": "ENABLED"
1457+
}
1458+
}
14201459
}
14211460
}

tests/aws/services/dynamodb/test_dynamodb.validation.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
"tests/aws/services/dynamodb/test_dynamodb.py::TestDynamoDB::test_dynamodb_streams_describe_with_exclusive_start_shard_id": {
5454
"last_validated_date": "2023-10-22T20:27:28+00:00"
5555
},
56+
"tests/aws/services/dynamodb/test_dynamodb.py::TestDynamoDB::test_dynamodb_update_table_without_sse_specification_change": {
57+
"last_validated_date": "2024-12-09T16:09:21+00:00"
58+
},
5659
"tests/aws/services/dynamodb/test_dynamodb.py::TestDynamoDB::test_empty_and_binary_values": {
5760
"last_validated_date": "2023-08-23T14:32:29+00:00"
5861
},

0 commit comments

Comments
 (0)