Skip to content

mjehrhart/lambda-rust-weatherstation-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About this Project

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.

AWS Lambda & Rust Deployment Method

                  

Prerequisite

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.

Setup

Open your mac terminal to your projects home directory

  • git clone https://github.com/mjehrhart/sam-rust-template.git or use sam init for a new install
  • make 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.

Commands

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 or make bootstrap_debug

Deploy to AWS

  • make deploy

Testing Options

  • 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 or make 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.

Cleanup

  • sam delete

Helpful Links

Screenshots

Makefile

Here is what my Makefile looks like. It works great for me.

images/Screen Shot 2022-05-11 at 10.04.38 AM_gOO0tQxBTQudo5Re.png

template.yaml

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.

images/Screen Shot 2022-05-10 at 10.00.09 AM_NDCdNwvovL0Tjp0Y.png

About

Was asked to share this code with reddit users. Good luck.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published