Skip to content

Commit 0cc2ccd

Browse files
committed
fix DynamoDB TableARN which is hardcoded as "ddblocal" in DynamoDBLocal
1 parent f2863d2 commit 0cc2ccd

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

localstack/services/dynamodb/dynamodb_listener.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import json
23
import random
34
import logging
@@ -34,6 +35,14 @@ def return_response(self, method, path, data, headers, response):
3435
if data and 'TableName' in data and 'KeySchema' in data:
3536
TABLE_DEFINITIONS[data['TableName']] = data
3637

38+
if response._content:
39+
# fix the table ARN (DynamoDBLocal hardcodes "ddblocal" as the region)
40+
content_replaced = re.sub(r'"TableArn"\s*:\s*"arn:aws:dynamodb:ddblocal:([^"]+)"',
41+
r'"TableArn": "arn:aws:dynamodb:%s:\1"' % aws_stack.get_local_region(), to_str(response._content))
42+
if content_replaced != response._content:
43+
response._content = content_replaced
44+
fix_headers_for_updated_response(response)
45+
3746
action = headers.get('X-Amz-Target')
3847
if not action:
3948
return
@@ -98,8 +107,7 @@ def return_response(self, method, path, data, headers, response):
98107
'TableName': data['TableName']
99108
}
100109
response._content = json.dumps(content)
101-
response.headers['content-length'] = len(response.content)
102-
response.headers['x-amz-crc32'] = calculate_crc32(response)
110+
fix_headers_for_updated_response(response)
103111
elif action == '%s.DeleteItem' % ACTION_PREFIX:
104112
record['eventName'] = 'REMOVE'
105113
record['dynamodb']['Keys'] = data['Key']
@@ -131,6 +139,11 @@ def return_response(self, method, path, data, headers, response):
131139
UPDATE_DYNAMODB = ProxyListenerDynamoDB()
132140

133141

142+
def fix_headers_for_updated_response(response):
143+
response.headers['content-length'] = len(response.content)
144+
response.headers['x-amz-crc32'] = calculate_crc32(response)
145+
146+
134147
def calculate_crc32(response):
135148
return crc32(to_bytes(response.content)) & 0xffffffff
136149

0 commit comments

Comments
 (0)