I think it’s time to realize that Netlify functions (AWS lambda) using rust is not only feasible, it’s definitely worth a try to use if you are also building your site with a Rust web framework and want to keep everything Rust.
I respectfully disagree with the Ask Netlify
AI bot .
Here is a gist of a Netlify function I setup to connect to a Postgres database on the Neon service:
Remember, Netlify functions are really just AWS Lambda functions underneath and you can use the lambda_runtime
crate along with others to make some really nice type safe functions.
Crates worth mentioning:
diesel
anddiesel-async
andbb8
tokio
(required),tokio-postgres
, andtokio-postgres-rustls
for TLS connection to database
Using diesel will allow me to use the types on my frontend Rust framework web app (Leptos Starter) while using them in the Netlify functions from the same workspace repo. Testing can be done through the diesel database crate you setup separately. Later I may decide to go SSR and all this work would already be setup and just move the functions to the backend code on the server.
diesel-async
allows for a TLS
connection using tokio-postgres-rustls
. The function example uses a pool of connections using bb8
to the database to allow for auto scaling of the connections to the database in the case of high usage Something the javascript serverless Neon sdk may not have available (need to research).
An amazing finding when I finally got the function up and running was the speed of the lambda connection to the Neon database. Of course, it was a small amount of data, but the round trip from the lamda server to the database server was better than I expected for sure.
Note: The Neon database has a Netlify integration using javascript for those of you who don’t want to learn rust or have a need for a Postgres solution. As of this writing, Neon has a decent free plan to experiment. It should be fairly easy to setup a Netlify function and use @neondatabase/serverless
.