Created
December 10, 2017 22:09
-
-
Save ytaminE/523c53c5c73087e38879ba25e31120c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import urllib2 | |
| import StringIO | |
| import sys | |
| import contextlib | |
| import ast | |
| @contextlib.contextmanager | |
| def stdoutIO(stdout=None): | |
| old = sys.stdout | |
| if stdout is None: | |
| stdout = StringIO.StringIO() | |
| sys.stdout = stdout | |
| yield stdout | |
| sys.stdout = old | |
| def lambda_handler(event, context): | |
| name = event['name'] | |
| response = urllib2.urlopen(event['url']) | |
| input = event['input'] | |
| input = ast.literal_eval(input) | |
| code = response.read() | |
| with stdoutIO() as s: | |
| try: | |
| exec(code) | |
| result = locals()[name](input) | |
| print result | |
| except Exception as err: | |
| return "Unexpected error:" + str(err) | |
| return s.getvalue() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment