|
| 1 | +import re |
1 | 2 | import json
|
2 | 3 | import random
|
3 | 4 | import logging
|
@@ -34,6 +35,14 @@ def return_response(self, method, path, data, headers, response):
|
34 | 35 | if data and 'TableName' in data and 'KeySchema' in data:
|
35 | 36 | TABLE_DEFINITIONS[data['TableName']] = data
|
36 | 37 |
|
| 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 | + |
37 | 46 | action = headers.get('X-Amz-Target')
|
38 | 47 | if not action:
|
39 | 48 | return
|
@@ -98,8 +107,7 @@ def return_response(self, method, path, data, headers, response):
|
98 | 107 | 'TableName': data['TableName']
|
99 | 108 | }
|
100 | 109 | 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) |
103 | 111 | elif action == '%s.DeleteItem' % ACTION_PREFIX:
|
104 | 112 | record['eventName'] = 'REMOVE'
|
105 | 113 | record['dynamodb']['Keys'] = data['Key']
|
@@ -131,6 +139,11 @@ def return_response(self, method, path, data, headers, response):
|
131 | 139 | UPDATE_DYNAMODB = ProxyListenerDynamoDB()
|
132 | 140 |
|
133 | 141 |
|
| 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 | + |
134 | 147 | def calculate_crc32(response):
|
135 | 148 | return crc32(to_bytes(response.content)) & 0xffffffff
|
136 | 149 |
|
|
0 commit comments