Last active
April 2, 2024 17:37
-
-
Save vaclavcadek/15e1b7496690c0649b61ada2aa13e72d to your computer and use it in GitHub Desktop.
Simple example of AWS Lambda + custom image, usage: 1) docker build . -t test/hello-world 2) docker run --rm -p 9000:8080 test/hello-world:latest 3) curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"foo": "test"}'
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 sys | |
def handler(event, context): | |
print(context) | |
print(event) | |
return 'Hello from AWS Lambda using Python' + sys.version + '!' |
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
FROM python:3.8-alpine | |
# Define global args | |
ARG FUNCTION_DIR="/home/app/" | |
RUN apk add --no-cache \ | |
libstdc++ | |
# Install aws-lambda-cpp build dependencies | |
RUN apk add --no-cache \ | |
build-base \ | |
libtool \ | |
autoconf \ | |
automake \ | |
libexecinfo-dev \ | |
make \ | |
cmake \ | |
libcurl | |
# Create function directory | |
# Copy handler function | |
ADD app.py ${FUNCTION_DIR} | |
# Install Lambda Runtime Interface Client for Python | |
RUN pip install awslambdaric | |
# Set working directory to function root directory | |
WORKDIR ${FUNCTION_DIR} | |
# (Optional) Add Lambda Runtime Interface Emulator and use a script in the ENTRYPOINT for simpler local runs | |
ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/bin/aws-lambda-rie | |
COPY entry.sh / | |
RUN chmod 755 /usr/bin/aws-lambda-rie /entry.sh | |
ENTRYPOINT [ "/entry.sh" ] | |
CMD [ "app.handler" ] |
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
#!/bin/sh | |
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then | |
exec /usr/bin/aws-lambda-rie /usr/local/bin/python -m awslambdaric $1 | |
else | |
exec /usr/local/bin/python -m awslambdaric $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment