This rust lambda connects to dynamodb to return a JSON result set utilizing the API Gateway. All files needed to build/compile/deploy for AWS are located in this repo. There are a couple Readme files to help out. I hope the files are helpful.
This guide is written for macOS users. Make sure you have these following items installed and configured if needed. Installing these items takes only a few minutes. This guide will help you deploy rust lambdas into AWS using SAM CLI along with Docker. Plus you can test locally using SAM CLI as well. Save time by not deploying until you want too.
-
Docker - container for building cross compilation
https://docs.docker.com/get-started/ -
Artillery - used for rapid testing
npm install -g artillery@latest
Open your mac terminal to your projects home directory
git clone https://github.com/mjehrhart/sam-rust-template.git
or usesam init
for a new installmake setup
(uses the Makefile from this repo)- Make any changes to Makefile
- Make any changes to template.yaml
Once all this is done, go ahead and do your coding stuff. As of the time of writing this, various rust crates do not work in AWS lambda or at least I haven't been able to get them to work. So be careful and take your time testing crates. For me, it was a lot of trial and error.
Using Docker with SAM CLI is preferred for the build
alias rust-musl-builder='docker run --rm -it -v "$(pwd)":/home/rust/src ekidd/rust-musl-builder'
rust-musl-builder cargo build --release
Build
make bootstrap
ormake bootstrap_debug
Deploy to AWS
make deploy
-
make tests-unit
-
make tests-integ
-
sam local start-api
(only restart server if changes to template.yaml are made )
Update Changes to test locally with SAM CLI
-
rust-musl-builder cargo build --release
(takes a few minutes) -
make bootstrap
ormake bootstrap_debug
-
open browser to http://127.0.0.1:3000
-
SAM CLI will work off of the updated bootstrap file. That is why we update it here after any changes to the code.
sam delete
Here is what my Makefile looks like. It works great for me.
Note the CodeUri points to the build/ directory. This is where the bootstrap file be put. So the CodeUri points to the location of the bootstrap for that function.