| 112 | ) |
| 113 | |
| 114 | def save_file(self, parsed, **kwargs): |
| 115 | # This method is hooked into after-call which fires |
| 116 | # before the error checking happens in the client. |
| 117 | # Therefore if the stream_key is not in the parsed |
| 118 | # response we immediately return and let the default |
| 119 | # error handling happen. |
| 120 | if self._stream_key not in parsed: |
| 121 | return |
| 122 | event_stream = parsed[self._stream_key] |
| 123 | with open(self._output_file, 'wb') as fp: |
| 124 | for event in event_stream: |
| 125 | if 'Records' in event: |
| 126 | fp.write(event['Records']['Payload']) |
| 127 | # We don't want to include the streaming param in |
| 128 | # the returned response, it's not JSON serializable. |
| 129 | del parsed[self._stream_key] |