Last active
November 19, 2018 01:47
-
-
Save jaysonsantos/c91c79ab5505ffd2063081b7c10ce9d3 to your computer and use it in GitHub Desktop.
Rust AWS Lambda Builder and Runner
This file contains 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
target/* |
This file contains 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 lambci/lambda-base:build | |
ENV RUSTUP_HOME=/usr/local/rustup \ | |
CARGO_HOME=/usr/local/cargo \ | |
PATH=/usr/local/cargo/bin:$PATH \ | |
RUST_VERSION=1.27.2 | |
RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable --no-modify-path -y && \ | |
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \ | |
rustup --version; \ | |
cargo --version; \ | |
rustc --version; \ | |
yum install gcc -y | |
This file contains 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
BINARY_NAME=lambda-test | |
RELEASE_FOLDER=target/x86_64-unknown-linux-gnu/release | |
USERID=$(shell id -u ${USER}) | |
GROUPID=$(shell id -g ${USER}) | |
target/docker-image: Dockerfile.lambda-builder | |
docker build -t rust-amazonlinux -f Dockerfile.lambda-builder . | |
touch $@ | |
target/cached_data: | |
mkdir -p target/cached_data | |
${RELEASE_FOLDER}/${BINARY_NAME}: target/cached_data src/*.rs | |
docker run --rm \ | |
-v ${PWD}/target/cached_data:/usr/local/cargo/registry \ | |
-v ${PWD}:/code \ | |
-w /code \ | |
-u ${USERID}:${GROUPID} \ | |
rust-amazonlinux \ | |
bash -c ' \ | |
set -e -x; \ | |
cargo build --target x86_64-unknown-linux-gnu --release; \ | |
du -h ${RELEASE_FOLDER}/${BINARY_NAME}; \ | |
strip ${RELEASE_FOLDER}/${BINARY_NAME}; \ | |
du -h ${RELEASE_FOLDER}/${BINARY_NAME}; \ | |
' | |
main.zip: target/docker-image ${RELEASE_FOLDER}/${BINARY_NAME} | |
cp ${RELEASE_FOLDER}/${BINARY_NAME} main | |
zip -D main.zip main | |
du -h main.zip | |
rm -rf main | |
run: target/docker-image ${RELEASE_FOLDER}/${BINARY_NAME} | |
docker run --rm \ | |
-v "${PWD}/${RELEASE_FOLDER}/":/var/task \ | |
lambci/lambda:go1.x \ | |
${BINARY_NAME} \ | |
'{"some": "event"}' | |
.PHONY=run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment