• Stars
    star
    161
  • Rank 225,231 (Top 5 %)
  • Language
    Shell
  • License
    MIT License
  • Created over 5 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿณ ๐Ÿฆ€ a dockerized lambda build env for rust applications

AWS Lambda Rust docker builder ๐Ÿ‘ ๐Ÿฆ€ ๐Ÿณ Build Status

๐Ÿค” about

This docker image extends lambda ci provided.al2 builder docker image, a faithful reproduction of the actual AWS "provided.al2" Lambda runtime environment, and installs rustup and the stable rust toolchain.

This provides a build environment, consistent with your target execution environment for predictable results.

๐Ÿ“ฆ install

Tags for this docker image follow the naming convention softprops/lambda-rust:{version}-rust-{rust-stable-version} where {rust-stable-version} is a stable version of rust.

You can find a list of available docker tags here

๐Ÿ’ก If you don't find the version you're looking for, please open a new github issue to publish one

You can also depend directly on softprops/lambda-rust:latest for the most recently published version.

๐Ÿคธ usage

The default docker entrypoint will build a packaged release optimized version of your Rust artifact under target/lambda/release to isolate the lambda specific build artifacts from your host-local build artifacts.

โš ๏ธ Note: you can switch from the release profile to a custom profile like dev by providing a PROFILE environment variable set to the name of the desired profile. i.e. -e PROFILE=dev in your docker run

โš ๏ธ Note: you can include debug symbols in optimized release build binaries by setting DEBUGINFO. By default, debug symbols will be stripped from the release binary and set aside in a separate .debug file.

You will want to volume mount /code to the directory containing your cargo project.

You can pass additional flags to cargo, the Rust build tool, by setting the CARGO_FLAGS docker env variable.

Unzipped boostrap and boostrap.debug files are always available under target/lambda/${PROFILE}/output/${BIN} dir. If you want only them and don't need a .zip archive (e.g. for when running lambdas locally) pass -e PACKAGE=false flag. More on that in local testing.

A typical docker run might look like the following.

$ docker run --rm \
    -u $(id -u):$(id -g) \
    -v ${PWD}:/code \
    -v ${HOME}/.cargo/registry:/cargo/registry \
    -v ${HOME}/.cargo/git:/cargo/git \
    softprops/lambda-rust

๐Ÿ’ก The -v (volume mount) flags for /cargo/{registry,git} are optional but when supplied, provides a much faster turn around when doing iterative development

Note that -u $(id -u):$(id -g) argument is crucial for the container to produce artifacts owned by the current host user, otherwise you won't be able to rm -rf target/lambda or run cargo update, because the container will write artifacts owned by root docker user to target/lambda and ./cargo/{registry,git} dirs which will break your dev and/or ci environment.

You should also ensure that you do have ${HOME}/.cargo/{registry,git} dirs created on your host machine, otherwise docker will create them automatically and assign root user as an owner for these dirs which is unfortunate...

If you are using Windows, the command above may need to be modified to include a BIN environment variable set to the name of the binary to be build and packaged

$ docker run --rm \
    -u $(id -u):$(id -g) \
+   -e BIN={your-binary-name} \
    -v ${PWD}:/code \
    -v ${HOME}/.cargo/registry:/cargo/registry \
    -v ${HOME}/.cargo/git:/cargo/git \
    softprops/lambda-rust

For more custom codebases, the '-w' argument can be used to override the working directory. This can be especially useful when using path dependencies for local crates.

$ docker run --rm \
    -u $(id -u):$(id -g) \
    -v ${PWD}/lambdas/mylambda:/code/lambdas/mylambda \
    -v ${PWD}/libs/mylib:/code/libs/mylib \
    -v ${HOME}/.cargo/registry:/cargo/registry \
    -v ${HOME}/.cargo/git:/cargo/git \
    -w /code/lambdas/mylambda \
    softprops/lambda-rust

โš“ using hooks

If you want to customize certain parts of the build process, you can leverage hooks that this image provides. Hooks are just shell scripts that are invoked in a specific order, so you can customize the process as you wish. The following hooks exist:

  • install: run before cargo build - useful for installing native dependencies on the lambda environment
  • build: run after cargo build, but before packaging the executable into a zip - useful when modifying the executable after compilation
  • package: run after packaging the executable into a zip - useful for adding extra files into the zip file

The hooks' names are predefined and must be placed in a directory .lambda-rust in the project root.

You can take a look at an example here.

๐Ÿ”ฌ local testing

Once you've built a Rust lambda function artifact, the provided.al2 runtime expects deployments of that artifact to be named "bootstrap". The lambda-rust docker image builds a zip file, named after the binary, containing your binary file renamed to "bootstrap" for you, but zip file creation is unnecessary for local development.

In order to prevent the creation of an intermediate .zip artifact when testing your lambdas locally, pass -e PACKAGE=false during the build. After that the necessary output (not zipped) is available under target/lambda/{profile}/output/{your-lambda-binary-name} dir. You will see both bootstrap and bootstrap.debug files there.

โš ๏ธ Note: PACKAGE=false prevents package hook from running.

You can then invoke this bootstap executable with the lambda-ci docker image for the provided.al2 AWS lambda runtime with a one off container.

# Build your function skipping the zip creation step
# You may pass `-e PROFILE=dev` to build using dev profile, but here we use `release`
docker run \
    -u $(id -u):$(id -g) \
    -e PACKAGE=false \
    -e BIN={your-binary-name} \
    -v ${PWD}:/code \
    -v ${HOME}/.cargo/registry:/cargo/registry \
    -v ${HOME}/.cargo/git:/cargo/git \
    softprops/lambda-rust

# start a one-off docker container replicating the "provided.al2" lambda runtime
# awaiting an event to be provided via stdin
$ docker run \
    -i -e DOCKER_LAMBDA_USE_STDIN=1 \
    --rm \
    -v ${PWD}/target/lambda/release/output/{your-binary-name}:/var/task:ro,delegated \
    lambci/lambda:provided.al2

# provide an event payload via stdin (typically a json blob)

# Ctrl-D to yield control back to your function

You may find the one-off container less than ideal if you wish to trigger your lambda multiple times. For these cases try using the "stay open" mode of execution.

# start a long running docker container replicating the "provided" lambda runtime
# listening on port 9001
$ unzip -o \
    target/lambda/release/{your-binary-name}.zip \
    -d /tmp/lambda && \
  docker run \
    --rm \
    -v /tmp/lambda:/var/task:ro,delegated \
    -e DOCKER_LAMBDA_STAY_OPEN=1 \
    -p 9001:9001 \
    lambci/lambda:provided.al2

In a separate terminal, you can invoke your function with curl

The -d flag is a means of providing your function's input.

$ curl -d '{}' \
    http://localhost:9001/2015-03-31/functions/myfunction/invocations

You can also use the aws cli to invoke your function locally. The --payload is a means of providing your function's input.

$ aws lambda invoke \
    --endpoint http://localhost:9001 \
    --cli-binary-format raw-in-base64-out \
    --no-sign-request \
    --function-name myfunction \
    --payload '{}' out.json \
    && cat out.json \
    && rm -f out.json

๐Ÿคธ๐Ÿคธ usage via cargo aws-lambda subcommand

A third party cargo subcommand exists to compile your code into a zip file and deploy it. This comes with only rust and docker as dependencies.

Setup

$ cargo install cargo-aws-lambda

To compile and deploy in your project directory

$ cargo aws-lambda {your aws function's full ARN} {your-binary-name}

To list all options

$ cargo aws-lambda --help

More instructions can be found here.

Doug Tangren (softprops) 2020

More Repositories

1

action-gh-release

๐Ÿ“ฆ :octocat: GitHub Action for creating GitHub Releases
TypeScript
3,625
star
2

envy

deserialize env vars into typesafe structs with rust
Rust
758
star
3

shiplift

๐Ÿณ ๐Ÿฆ€ rust interface for maneuvering docker containers
Rust
593
star
4

serverless-rust

โšก ๐Ÿฆ€ a serverless framework plugin for rustlang applications
JavaScript
538
star
5

turnstyle

๐ŸŽŸ๏ธA GitHub Action for serializing workflow runs
TypeScript
286
star
6

hubcaps

a rust interface for github
Rust
280
star
7

atty

are you or are you not a tty?
Rust
254
star
8

dynomite

โšก๐Ÿฆ€ ๐Ÿงจ make your rust types fit DynamoDB and visa versa
Rust
213
star
9

hyperlocal

๐Ÿ”Œ โœจrustlang hyper bindings for local unix domain sockets
Rust
201
star
10

recap

deserialize typed structures from regex captures
Rust
165
star
11

cargo-thanks

๐Ÿ’– ๐Ÿฆ€ give thanks to your fellow Rustaceans
Rust
162
star
12

np

new sbt project generation made simple(r)
Scala
149
star
13

openapi

openapi schema serialization for rust
Rust
124
star
14

awesome-mdbook

๐Ÿ•ถ๏ธ๐Ÿ—ƒ๏ธ a card catalog of mdbooks for your reading curiosity
111
star
15

serverless-aws-rust

โšก๐Ÿ—๏ธ template for new aws lambda serverless rust apps
Rust
96
star
16

serverless-aws-rust-http

โšก๐Ÿ—๏ธ template for new aws lambda serverless rust http apps
Rust
90
star
17

picture-show

slip and slide picture shows for the web
Scala
77
star
18

goji

a rust interface for jira
Rust
72
star
19

lando

๐Ÿ“ฆ ๐Ÿš€ a smooth-talking smuggler of Rust HTTP functions into AWS lambda
Rust
69
star
20

fasttime

โฑ๏ธ A Fastly serverless compute@edge runtime for running wasm applications locally
Rust
60
star
21

tugboat

a small boat used for maneuvering docker vessels
Scala
58
star
22

serverless-aws-rust-multi

โšก๐Ÿ—๏ธ template for new aws lambda serverless rust http apps
Rust
57
star
23

again

โ™ป๏ธ Retry faillible Rustlang std library futures
Rust
55
star
24

afterparty

rust github webhook server
Rust
55
star
25

coffeescripted-sbt

pour some coffee for scala
Scala
55
star
26

ls

[discontinued] a scala card catalog
Scala
54
star
27

sbt-growl-plugin

Growling sbt test results so you don't have to
Scala
54
star
28

less-sbt

type less css in your sbt projects
CSS
45
star
29

envy-store

๐Ÿช deserialize AWS Parameter Store values into type safe structs
Rust
39
star
30

hubcat

hip cats and git hubs
Scala
34
star
31

zoey

taking scala to the zoo
Scala
29
star
32

json-env-logger

A structured JSON logger for Rust.
Rust
29
star
33

serverless-aws-rust-websockets

โšก๐Ÿ—๏ธ template for new aws lambda websocket serverless rust apps
Rust
28
star
34

setup-aws-copilot

๐Ÿ‘ฉโ€โœˆ๏ธ A GitHub Action for setting up and configuring the AWS Copilot command line interface
TypeScript
25
star
35

treeline

rust in trees
Rust
25
star
36

semverfi

always faithful, always loyal semantic versioning
Scala
23
star
37

unplanned

instant http
Scala
21
star
38

base64

the 64th base of rfc4648
Scala
21
star
39

mint

a makefile linter
Rust
20
star
40

screenprints

reprints for your terminal screen
Rust
19
star
41

porteurbars

๐Ÿšฒ a tool for sharing portable git hosted project templates
Rust
19
star
42

git-codeowners

a git extension to work with CODEOWNERS files
Rust
19
star
43

heroic

zero to hero Heroku deployment for sbt
Scala
18
star
44

assembly-sbt

Deploy fat JARs. Restart processes.
Scala
18
star
45

cappi

the sweetest sbt plugin your microbenchmarks will ever meet
Scala
17
star
46

capgun

fire when ready
Rust
15
star
47

tubesocks

A comfortable and fashionable way to have bi-directional conversations with modern web servers.
Scala
14
star
48

ryu

A `Tornado Whirlwind Kick` scala client for the riak `raw` http interface
Scala
13
star
49

pine

process line output
Rust
13
star
50

waitout

awaits the completion of multiple async tasks
Rust
12
star
51

scuttlebutt

Listen in on all the gossip going on in your kubernetes cluster ๐Ÿ™Š
Rust
12
star
52

emoji-clock

๐Ÿ•’ ๐Ÿ‡ I'm late I'm late for a very important date
Rust
12
star
53

rust-bin

๐Ÿ—๏ธ๐Ÿ—‘๏ธ a recipe for Rust bins built, tested, and published with GitHub Actions
Shell
11
star
54

termsize

terminal size matters
Rust
11
star
55

unisockets

unix domain sockets that look just like tcp sockets
Scala
11
star
56

meow

a scala growl client that purs
Scala
11
star
57

serverless-aws-rust-kinesis

โšก๐Ÿ—๏ธ template for new aws lambda serverless kinesis rust apps
Rust
11
star
58

zig-lambda-runtime

an aws lambda runtime for zig
Zig
11
star
59

northeast-scala-symposium

event site for the northeast scala symposium
Scala
11
star
60

typed-lambda

ฮป formal type definitions for aws lambda events
Makefile
10
star
61

sigv4

๐Ÿ”โœ๏ธ aws sigv4 signed requests on the command line
Rust
10
star
62

codeowners

a rust crate for working with CODEOWNERS files
Rust
9
star
63

captcha_with_question

First attempt at a rails plugin. A form captcha with a textual question.
Ruby
9
star
64

treeline-scala

Renders nested tree branches in unicode and ascii
Scala
9
star
65

jot

just a thought
Scala
9
star
66

unfiltered-websockets.g8

unfiltered websockets g8 template
Scala
9
star
67

serverless-localhost

TypeScript
9
star
68

diffset

A GitHub Action for producing lists of files that changed between branches
TypeScript
8
star
69

aws-crossing

๐Ÿšธ Do cross AWS account work more efficiently
Rust
8
star
70

aws-credential-rotary

TypeScript
8
star
71

tee

tee for rustlang readers
Rust
8
star
72

serverless-yml-schema

a json schema file for serverless framework's serverless.yml file
8
star
73

guavapants

one pair of pants that makes both your guava _and_ scala types look good
Scala
8
star
74

serverless-lando

โšก๐Ÿ—๏ธ template for new serverless lando apps
Makefile
8
star
75

sinatra-doc

self documentaion for your sinatra app's routes
Ruby
7
star
76

serverless-oncall

โšก๐Ÿ“Ÿ Easily manage oncall for your serverless services
TypeScript
7
star
77

serverless-crowbar

โšก๐Ÿ—๏ธtemplate for new serverless crowbar apps
Makefile
7
star
78

action-time

7
star
79

unfiltered-gae.g8

unfiltered google app engine g8 template
Scala
7
star
80

gist

it's like git with an s between the i and t
Scala
7
star
81

sox

comfortable, well fitting documentation for your sbt settings
Scala
6
star
82

spakle

โ–โ–‡โ–โ–„โ–ƒโ–‚โ–„โ–„โ–†โ–†โ–…โ–ƒโ–…โ–โ–‚ just like nyc's skyline (or something like that)
Scala
6
star
83

dispatch-foursquare

databinder dispatch interface for foursquare api
Scala
6
star
84

muxup

demo meetup api python app
Python
6
star
85

porthole

tiny rust crate for resolving the next available network port
Rust
6
star
86

zig-envy

parse env variables into zig structs
Zig
6
star
87

unfiltered-basic-auth.g8

unfiltered basic auth example g8 template
Scala
5
star
88

pj

a pajama party for your json strings and streamers
Scala
5
star
89

opener

everyone loves a good opener
Scala
5
star
90

ls-sbt

shhhh not ready yet
Scala
5
star
91

unfiltered.g8

template for unfiltered app
Scala
5
star
92

ls-server

[discontinued] scala's local librarian
Scala
5
star
93

zig-graphql

a basic GraphQL client for zig
Zig
5
star
94

chrome-plugin.g8

g8 template for google chrome plugins
Scala
5
star
95

track-jacket

A slimly outfitted interface for getting your app up and running with marathon
Scala
4
star
96

stats

exporter of numbers, speaks statsd
Scala
4
star
97

enroute

๐Ÿ›ฉ๏ธ a parsimonious http request router
Rust
4
star
98

sing

Scala
4
star
99

xray

๐Ÿ•ต๏ธ aws xray daemon client for rustlang applications
Rust
4
star
100

broadcast

A rustlang adapter for writing to multiple sources
Rust
4
star