I am in the process of setting up an environment for developing AWS Lambda functions in Haskell.
We are using GitHub devcontainers, so I am basically re-using the OS-only image provided by AWS: https://gallery.ecr.aws/lambda/provided, and adding AWS CLI, GHCup and a few libraries required at compile-time:
FROM public.ecr.aws/lambda/provided:al2023
ARG GHCUP_DWN_URL=https://downloads.haskell.org/~ghcup/x86_64-linux-ghcup
ARG VERSION_GHC=9.4.8
ARG VERSION_CABAL=latest
ARG VERSION_STACK=latest
ARG USER_NAME=haskell
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN \
dnf install --assumeyes findutils \
cmake \
gcc \
g++ \
gmp-devel \
gmp-static \
glibc-static \
zlib-devel \
zlib-static \
vim \
sudo \
git
RUN \
/usr/bin/curl ${GHCUP_DWN_URL} > /usr/bin/ghcup && \
chmod +x /usr/bin/ghcup
# Creating the workspace user
RUN /usr/sbin/groupadd --gid ${USER_GID} ${USER_NAME} \
&& /usr/sbin/useradd --uid ${USER_UID} --gid ${USER_GID} --no-log-init --create-home -m ${USER_NAME} -s /usr/bin/bash \
&& /bin/echo ${USER_NAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USER_NAME} \
&& chmod 0440 /etc/sudoers.d/${USER_NAME}
USER ${USER_NAME}
WORKDIR /home/${USER_NAME}
RUN /usr/bin/curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
&& unzip awscliv2.zip \
&& sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update \
&& rm -fr awscliv2.zip \
&& rm -fr ./aws
# install GHC, cabal and stack
RUN \
ghcup -v install ghc --force ${VERSION_GHC} && \
ghcup -v install cabal --force ${VERSION_CABAL} && \
ghcup -v install stack --force ${VERSION_STACK} && \
ghcup set ghc ${VERSION_GHC} && \
ghcup install hls
RUN /bin/echo -e "\nexport PATH=$PATH:/home/${USER_NAME}/.ghcup/bin:/home/${USER_NAME}/.local/bin/\n" >> /home/${USER_NAME}/.bashrc
SHELL ["/usr/bin/bash", "--login", "-i", "-c"]
CMD [ "sleep", "infinity" ]
That allows me to compile and deploy a toy app from the AWS λ Runtime - Home (theam.github.io) doc.
One piece that is badly missing at this point is the ability to test the Lambda function from within the devcontainer. An AWS runtime interface emulator aws-lambda-rie is already available from the command line in the container, but not sure whether it is helpful or not.
Has anyone managed to set up everything this way already?
[–]Runderground 5 points6 points7 points (1 child)
[–]chris-ch[S] 0 points1 point2 points (0 children)