DynamoDB: Support sending nested items to ESM's (#6559)

This commit is contained in:
Bert Blommers 2023-07-24 21:34:36 +00:00 committed by GitHub
parent 6b0d022925
commit 1670471068
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -302,7 +302,14 @@ class Item(BaseModel):
def to_json(self) -> Dict[str, Any]:
attributes = {}
for attribute_key, attribute in self.attrs.items():
attributes[attribute_key] = {attribute.type: attribute.value}
if isinstance(attribute.value, dict):
attr_value = {
key: value.to_regular_json()
for key, value in attribute.value.items()
}
attributes[attribute_key] = {attribute.type: attr_value}
else:
attributes[attribute_key] = {attribute.type: attribute.value}
return {"Attributes": attributes}

View File

@ -136,7 +136,8 @@ def test_invoke_function_from_dynamodb_put():
assert response["EventSourceArn"] == table["TableDescription"]["LatestStreamArn"]
assert response["State"] == "Enabled"
dynamodb.put_item(TableName=table_name, Item={"id": {"S": "item 1"}})
item_to_create = {"id": {"S": "item 1"}, "data": {"M": {"nested": {"S": "stuff"}}}}
dynamodb.put_item(TableName=table_name, Item=item_to_create)
expected_msg = "get_test_zip_file3 success"
log_group = f"/aws/lambda/{function_name}"
@ -145,6 +146,9 @@ def test_invoke_function_from_dynamodb_put():
assert msg_showed_up, (
expected_msg + " was not found after a DDB insert. All logs: " + str(all_logs)
)
assert any(
[json.dumps(item_to_create, separators=(",", ":")) in msg for msg in all_logs]
)
@pytest.mark.network