Skip to content
This repository has been archived by the owner on Dec 26, 2021. It is now read-only.
/ rust-sam-lambda Public archive

Sample of building a serverless application in Rust using AWS SAM

Notifications You must be signed in to change notification settings

smacintyre/rust-sam-lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getting started with Rust and AWS SAM

Goals

Assumptions

Installing Prerequisits

Install Rust

Install rustup, the Rust installer and version manager. Run the following command and follow the instructions on screen. You should be able to just accept the defaults.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

To verify the installation was successful run:

cargo --version

And you should see outpup like:

cargo 1.43.0 (2cbe9048e 2020-05-03)

Install musl libc tools

AWS Lambda will run our function in an Amazon Linux Environment. So we will use musl libc "libc" implementaiton so we can staticly link our binaries for running on Lambda. We will use this to eliminates the need an EC2 instance with Amazon Linux to compile our lambda functions.

macOS

The musl libc tools are installed via Homebrew. Please make sure you have it installed before proceeding.

Install the target for musl:

rustup target add x86_64-unknown-linux-musl

Install musl-tools:

brew install filosottile/musl-cross/musl-cross

Linux

Install the target for musl:

rustup target add x86_64-unknown-linux-musl

Install musl-tools:

sudo apt install musl-tools

Install AWS SAM CLI

We require SAM CLI v0.50+. The SAM CLI is installed via Homebrew on both macOS and Linux. Please make sure those are installed and follow these instructions. For full installation details, please see the offical docs.

Install the CLI

brew tap aws/tap
brew install aws-sam-cli

Verify the installation

sam --version

We require version 0.50.0 or greater:

SAM CLI, version 0.51.0

Docker (Optional)

Docker is required for local invocation. However, only a small portion of AWS' infastructure can be simulated locally via Docker. So this can be of limited use.

A note about linking on macOS

Under macOS we need to tell cargo about our musl based linker. So we have added a config file in the .cargo directory: .cargo/config

[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"

A note on debug and release builds

Currently this project is set to only do debug builds. In the future, I plan the ability to switch between build and debug. And, hopefully, add local debugging.

A note about the GNU Make Standard Library

The files gsml and __gsml are the GNU Make Standard Library or GMSL. They provide useful functions but so far we are only using lc to lowercase strings. This might be overkill when we could be using the stardard shell command tr. But I expect as more functionality is added to this project more will be used. The GMSL is released under the BSD License.

Running

Building

Deploying

Inspirations and Sources

About

Sample of building a serverless application in Rust using AWS SAM

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published