Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed561f0

Browse files
Baccatawhummer
authored andcommitted
Added "oldImage" data to dynamo events reflecting deletions (localstack#640)
* Adds the OldImage data so that when a listener of the dynamodb stream receives a deletion event, he's able to inspect the data that was deleted.
1 parent b2327be commit ed561f0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

‎localstack/services/dynamodb/dynamodb_listener.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def forward_request(self, method, path, data, headers):
3838
return error_response_throughput()
3939

4040
action = headers.get('X-Amz-Target')
41-
if action in ('%s.PutItem' % ACTION_PREFIX, '%s.UpdateItem' % ACTION_PREFIX):
41+
if action in ('%s.PutItem' % ACTION_PREFIX, '%s.UpdateItem' % ACTION_PREFIX, '%s.DeleteItem' % ACTION_PREFIX):
4242
# find an existing item and store it in a thread-local, so we can access it in return_response,
4343
# in order to determine whether an item already existed (MODIFY) or not (INSERT)
4444
ProxyListenerDynamoDB.thread_local.existing_item = find_existing_item(data)
@@ -164,8 +164,10 @@ def return_response(self, method, path, data, headers, response):
164164
response._content = json.dumps(content)
165165
fix_headers_for_updated_response(response)
166166
elif action == '%s.DeleteItem' % ACTION_PREFIX:
167+
old_item = ProxyListenerDynamoDB.thread_local.existing_item
167168
record['eventName'] = 'REMOVE'
168169
record['dynamodb']['Keys'] = data['Key']
170+
record['dynamodb']['OldImage'] = old_item
169171
elif action == '%s.CreateTable' % ACTION_PREFIX:
170172
if 'StreamSpecification' in data:
171173
create_dynamodb_stream(data)

0 commit comments

Comments
 (0)