Skip to content

Instantly share code, notes, and snippets.

@alexanderankin
Last active October 17, 2023 01:06
Show Gist options
  • Save alexanderankin/6adea44ef7196e0163fbb64dced36a60 to your computer and use it in GitHub Desktop.
Save alexanderankin/6adea44ef7196e0163fbb64dced36a60 to your computer and use it in GitHub Desktop.
# Define custom function directory
ARG FUNCTION_DIR="/function"
FROM node:18-buster as build-image
# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Install aws-lambda-cpp build dependencies
RUN apt-get update && \
apt-get install -y \
g++ \
make \
cmake \
unzip \
libcurl4-openssl-dev
# Copy function code
RUN mkdir -p ${FUNCTION_DIR}
COPY package.json package-lock.json ${FUNCTION_DIR}
WORKDIR ${FUNCTION_DIR}
# not ignoring scripts here because scripts build the c++ (bad, amazon)
RUN npm ci --production
# If the dependency is not in package.json uncomment the following line
# RUN npm install aws-lambda-ric
# Grab a fresh slim copy of the image to reduce the final size
FROM alpine
# maybe remove npm
RUN apk --update --no-cache add nodejs npm
# Required for Node runtimes which use [email protected]+ because
# by default npm writes logs under /home/.npm and Lambda fs is read-only
ENV NPM_CONFIG_CACHE=/tmp/.npm
# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Set working directory to function root directory
WORKDIR ${FUNCTION_DIR}
# Copy in the built dependencies
COPY . ${FUNCTION_DIR}
COPY --from=build-image ${FUNCTION_DIR}/node_modules ${FUNCTION_DIR}/node_modules
ENTRYPOINT ["/function/node_modules/.bin/aws-lambda-ric"]
CMD ["app.handler"]
# test with:
# https://github.com/aws/aws-lambda-nodejs-runtime-interface-client#local-testing
# mkdir -p ~/.aws-lambda-rie && \
# curl -Lo ~/.aws-lambda-rie/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie && \
# chmod +x ~/.aws-lambda-rie/aws-lambda-rie
# docker run -it --rm --name rie -p 9000:8080 \
# -v ~/.aws-lambda-rie:/aws-lambda --entrypoint /aws-lambda/aws-lambda-rie \
# $your_image /function/node_modules/.bin/aws-lambda-ric app.handler
#
# curl -X POST http://localhost:9000/2015-03-31/functions/function/invocations -d {} -vvv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment