DynamoDB: Support sending nested items to ESM's (#6559)
This commit is contained in:
parent
6b0d022925
commit
1670471068
@ -302,7 +302,14 @@ class Item(BaseModel):
|
|||||||
def to_json(self) -> Dict[str, Any]:
|
def to_json(self) -> Dict[str, Any]:
|
||||||
attributes = {}
|
attributes = {}
|
||||||
for attribute_key, attribute in self.attrs.items():
|
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}
|
return {"Attributes": attributes}
|
||||||
|
|
||||||
|
@ -136,7 +136,8 @@ def test_invoke_function_from_dynamodb_put():
|
|||||||
assert response["EventSourceArn"] == table["TableDescription"]["LatestStreamArn"]
|
assert response["EventSourceArn"] == table["TableDescription"]["LatestStreamArn"]
|
||||||
assert response["State"] == "Enabled"
|
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"
|
expected_msg = "get_test_zip_file3 success"
|
||||||
log_group = f"/aws/lambda/{function_name}"
|
log_group = f"/aws/lambda/{function_name}"
|
||||||
@ -145,6 +146,9 @@ def test_invoke_function_from_dynamodb_put():
|
|||||||
assert msg_showed_up, (
|
assert msg_showed_up, (
|
||||||
expected_msg + " was not found after a DDB insert. All logs: " + str(all_logs)
|
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
|
@pytest.mark.network
|
||||||
|
Loading…
Reference in New Issue
Block a user