python lambda function template
Install docker, jq, curl, build-essential etc...
## lambda function
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
# function called in Dockerfile
def lambda_handler(event, context):
logger.info('lambda handler invoked')
return {'message': 'Hello, World!'}
used image dockerhub
FROM public.ecr.aws/lambda/python:3.9
COPY requirements.txt .
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
COPY . ${LAMBDA_TASK_ROOT}
CMD [ "lambda_function.__main__.lambda_handler" ]
docker build . -t lambda-function
docker run --name python-lambda -d -p 9000:8080 lambda-function
curl -s -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}' | jq
all: build up test
.PHONY: all
make build
make up
make test
make clean