diff --git a/Dockerfile b/Dockerfile index f596900..f8931e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,13 @@ -FROM python:2.7 -RUN git clone https://github.com/HDE/python-lambda-local.git -RUN pip install ./python-lambda-local -# TODO: find all requirements.txt files and pip install them -ADD ./run_lambda_python.sh /usr/bin +FROM node:4 +RUN npm install -g lambda-local +# install image-magick +RUN apt-get update +RUN apt-get install -y imagemagick --fix-missing +# TODO: find all package.json files and npm install them globally +ADD ./run_lambda_node.sh /usr/bin # fixing up line-endings in case this container is run in a Windows environment -RUN sed -i -e 's/\r$//' /usr/bin/run_lambda_python.sh -RUN chmod +x /usr/bin/run_lambda_python.sh +RUN sed -i -e 's/\r$//' /usr/bin/run_lambda_node.sh +RUN chmod +x /usr/bin/run_lambda_node.sh RUN mkdir -p /usr/src VOLUME ["/usr/src/"] -ENTRYPOINT exec run_lambda_python.sh $FUNCTION_NAME docker +ENTRYPOINT exec run_lambda_node.sh $FUNCTION_NAME docker \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 4ff2e87..4c57152 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,25 @@ version: '2' services: lambda-python: - build: . + build: + context: . + dockerfile: dockerfiles/python/Dockerfile_python container_name: python-lambda-local volumes: - ./:/usr/src links: - dynamodb working_dir: /usr/src + lambda-node: + build: + context: . + dockerfile: dockerfiles/node/Dockerfile_node + container_name: node-lambda-local + volumes: + - ./:/usr/src + links: + - dynamodb + working_dir: /usr/src dynamodb: container_name: dynamodb-local image: modli/dynamodb diff --git a/dockerfiles/Dockerfile_node b/dockerfiles/Dockerfile_node new file mode 100644 index 0000000..f8931e0 --- /dev/null +++ b/dockerfiles/Dockerfile_node @@ -0,0 +1,13 @@ +FROM node:4 +RUN npm install -g lambda-local +# install image-magick +RUN apt-get update +RUN apt-get install -y imagemagick --fix-missing +# TODO: find all package.json files and npm install them globally +ADD ./run_lambda_node.sh /usr/bin +# fixing up line-endings in case this container is run in a Windows environment +RUN sed -i -e 's/\r$//' /usr/bin/run_lambda_node.sh +RUN chmod +x /usr/bin/run_lambda_node.sh +RUN mkdir -p /usr/src +VOLUME ["/usr/src/"] +ENTRYPOINT exec run_lambda_node.sh $FUNCTION_NAME docker \ No newline at end of file diff --git a/dockerfiles/Dockerfile_python b/dockerfiles/Dockerfile_python new file mode 100644 index 0000000..f596900 --- /dev/null +++ b/dockerfiles/Dockerfile_python @@ -0,0 +1,11 @@ +FROM python:2.7 +RUN git clone https://github.com/HDE/python-lambda-local.git +RUN pip install ./python-lambda-local +# TODO: find all requirements.txt files and pip install them +ADD ./run_lambda_python.sh /usr/bin +# fixing up line-endings in case this container is run in a Windows environment +RUN sed -i -e 's/\r$//' /usr/bin/run_lambda_python.sh +RUN chmod +x /usr/bin/run_lambda_python.sh +RUN mkdir -p /usr/src +VOLUME ["/usr/src/"] +ENTRYPOINT exec run_lambda_python.sh $FUNCTION_NAME docker diff --git a/lambda_functions/hello/hello.js b/lambda_functions/hello/hello.js new file mode 100644 index 0000000..1f07e8b --- /dev/null +++ b/lambda_functions/hello/hello.js @@ -0,0 +1,12 @@ +'use strict'; +console.log('Loading function'); + +exports.hello_handler = (event, context, callback) => { + //console.log('Received event:', JSON.stringify(event, null, 2)); + console.log('first name =', event.first_name); + console.log('last name =', event.last_name); + //callback(null, event.key1); // Echo back the first key value + // callback('Something went wrong'); + + context.done(null, 'great!'); +}; \ No newline at end of file diff --git a/run_lambda_node.sh b/run_lambda_node.sh new file mode 100644 index 0000000..a2b9c62 --- /dev/null +++ b/run_lambda_node.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +rm -rf /local_build/$1 +mkdir -p /local_build/$1 + +cp /usr/src/lambda_functions/$1/* /local_build/$1 +cp /usr/src/local_events/$1.json /local_build/$1 +cp /usr/src/config/* /local_build/$1 +cp /usr/src/lib/* /local_build/$1 + +cd /local_build/$1 +if [ -e "package.json" ] ; then + npm install . +fi + +echo "executing $1 function locally:" +lambda-local -l $1.js -h $1_handler -e $1.json \ No newline at end of file