Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support executable event file #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,8 @@ The output will be like:
None
[root - INFO - 2017-04-19 12:39:05,515] REPORT RequestId: b918f9ae-0ca1-44af-9937-dd5f9eeedcc1 Duration: 2.27 ms
```

#### Dynamic events:

Instead of an event.json file, any executable can be passed to `python-lambda-local` as the event path.
In this case, it will be executed, and its stdout will be used as the event.
10 changes: 8 additions & 2 deletions lambda_local/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
'''

import json
import os
import subprocess


def read_event(path):
with open(path) as event:
data = json.load(event)
if os.path.isfile(path) and os.access(path, os.X_OK):
r = subprocess.run(path, stdout=subprocess.PIPE)
data = json.loads(r.stdout)
else:
with open(path) as event:
data = json.load(event)

return data