Skip to content
GitHub Discord

Link multiple secrets

You might have multiple secrets that need to be used across your app. It can be tedious to create a new secret and link it to each function or resource.

A common pattern to addresses this is to create an object with all your secrets and then link them all at once. Now when you have a new secret, you can add it to the object and it will be automatically available to all your resources.

sst.config.ts
// Manage all secrets together
const secrets = {
secret1: new sst.Secret("Secret1", "some-secret-value-1"),
secret2: new sst.Secret("Secret2", "some-secret-value-2"),
};
const allSecrets = Object.values(secrets);
const bucket = new sst.aws.Bucket("MyBucket");
const api = new sst.aws.Function("MyApi", {
link: [bucket, ...allSecrets],
handler: "index.handler",
url: true,
});
index.ts
import { Resource } from "sst";
export function handler() {
console.log(`MyBucket: ${Resource.MyBucket.name}`);
console.log(`Secret1: ${Resource.Secret1.value}`);
console.log(`Secret2: ${Resource.Secret2.value}`);
return {
status: 200,
body: "Hello World!"
};
}

View the full example.