Skip to content

Instantly share code, notes, and snippets.

@willyg302
Last active May 15, 2016 09:43
Show Gist options
  • Save willyg302/c09048aeff3ae48ddcf2 to your computer and use it in GitHub Desktop.
Save willyg302/c09048aeff3ae48ddcf2 to your computer and use it in GitHub Desktop.
Python hello world from Lambda
config:
FunctionName: lambda-python
Handler: index.handler
Runtime: nodejs
Description: Python hello world from Lambda
install: make
<html>
<head>
</head>
<body>
<span id="python">Hello world from Python!</span>
</body>
</html>
var exec = require('child_process').exec;
exports.handler = function(event, context) {
child = exec('env/bin/python test.py', context.done);
child.stdout.on('data', function(data) {
console.log(data);
});
child.stderr.on('data', function(data) {
console.error(data);
});
};
VERSION = 12.0.5
VIRTUALENV = env
PYTHON = $(which python)
all:
wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-$(VERSION).tar.gz
tar xzf virtualenv-$(VERSION).tar.gz
$(PYTHON) virtualenv-$(VERSION)/virtualenv.py $(VIRTUALENV)
rm -rf virtualenv-$(VERSION)
rm virtualenv-$(VERSION).tar.gz
$(VIRTUALENV)/bin/pip install beautifulsoup4
from bs4 import BeautifulSoup
def main():
with open('index.html', 'r') as f:
soup = BeautifulSoup(f.read())
print(soup.find(id='python').text)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment