A little example serverless application, that you can deploy with the sam cli, using Rust as a custom runtime and building with Tide and tide-lambda-listener and using a PostgreSQL database to store the greetings
.
You check this post for a nice list of free-tier
offerings for a pg db.
db schema:
CREATE TABLE "public"."tide-lambda-example-greetings" (
"name" text NOT NULL,
"created_at" timestamp with time zone,
"modified_at" timestamp with time zone,
PRIMARY KEY ("name")
);
To build and deploy your application for the first time, you will need first to complete the DB_URL
in the template.yml
file with your database url and then run the following in your shell:
sam build
sam deploy --guided
This will deploy two lambda functions:
Save your greeting into the db
$ curl -X POST -d '{"name":"joe"}' https://<id>.execute-api.us-east-2.amazonaws.com/Prod/hello
Hello joe, welcome to this tide lambda example.
Retrive your greeting
curl https://<id>.execute-api.us-east-2.amazonaws.com/Prod/hello/joe
Hi again joe
SAM allow us to build each funcntion using a makefile
, we are using this file to file also to set the file
to use in our build.rs
file allowing to only compile the needed function endpoint and inject it into the main
function of our application.
This is an exploration and could be more efficient ways to conditional compile the code.
You will need to target x86_64-unknown-linux-musl
, you can check this article about custom runtimes.