Skip to content

Commit

Permalink
[lambda][rule] updating tests to go with previous commit and adding b…
Browse files Browse the repository at this point in the history
…ack a truncate call due to aws bug
  • Loading branch information
ryandeivert committed Apr 28, 2017
1 parent cf69fd7 commit 140b654
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions stream_alert/rule_processor/pre_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ def read_s3_file(cls, downloaded_s3_object):
for line in open(downloaded_s3_object, 'r'):
yield line.rstrip()

# aws lambda apparently does not reallocate disk space when files are
# removed using os.remove(), so we must truncate them before removal
with open(downloaded_s3_object, 'w'):
pass

# remove the file
os.remove(downloaded_s3_object)
if not os.path.exists(downloaded_s3_object):
Expand Down
5 changes: 3 additions & 2 deletions test/unit/test_pre_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def test_pre_parse_s3():
obj = s3_resource.Object(bucket_name, key_name)
obj.put(Body=body_value)

parsed = StreamPreParsers.pre_parse_s3(raw_record)
assert_equal(body_value, parsed[0])
s3_file = StreamPreParsers.pre_parse_s3(raw_record)
data = StreamPreParsers.read_s3_file(s3_file).next()
assert_equal(body_value, data)

BOTO_MOCKER.stop()

0 comments on commit 140b654

Please sign in to comment.