Reference

Quickstart

You’ll need to create a Secrets.toml file in your project root (if in a workspace, in the workspace root).

It should look like this:

Now you can annotate your Shuttle main function like so (using Axum as the example frameowrk):

Set your secrets as environment variables

If you are migrating from another platform to Shuttle, it is likely you are using a lot of environment variables.

shuttle_runtime::SecretStore implements IntoIter which allows you to iterate over the store. You can use this to set all of your environment variables like so:

main.rs
#[shuttle_runtime::main]
async fn main(
    #[shuttle_runtime::Secrets] secrets: shuttle_runtime::SecretStore
) -> shuttle_axum::ShuttleAxum {
    secrets.into_iter().for_each(|(key, val)| {
        std::env::set_var(key, val);
    });

    // rest of your code goes here
}

Note that each entry in SecretStore is a key-value pair, hence the destructuring.

How does it work?

At runtime, the secrets are read from the file (or from Shuttle’s servers if deployed) and provided as an immutable key-value store.