Skip to content

Secret

Reference doc for the `sst.Secret` component.

The Secret component lets you create secrets in your app.

Secrets are encrypted and stored in an S3 Bucket in your AWS account. If used in your app config, they’ll be encrypted in your state file as well. If used in your function code, they’ll be decrypted and stored in the function package.

Create a secret

const secret = new sst.Secret("MySecret");

Set a placeholder

You can optionally set a placeholder.

const secret = new sst.Secret("MySecret", "my-secret-placeholder-value");

Set the value of the secret

You can then set the value of a secret using the CLI.

Terminal
sst secret set MySecret my-secret-value

Use the secret in your app config

You can now use the secret in your app config.

sst.config.ts
console.log(mySecret.value);

You can link the secret to other resources, like a function or your Next.js app.

new sst.aws.Nextjs("MyWeb", {
link: [secret]
});

Once linked, you can use the secret in your function code.

app/page.tsx
import { Resource } from "sst";
console.log(Resource.MySecret.value);

Constructor

new Secret(name, placeholder?)

Parameters

  • name string

  • placeholder? string

    A placeholder value of the secret. This can be useful for cases where you might not be storing sensitive values.

Properties

name

Type Output<string>

The name of the secret.

placeholder

Type Output<undefined | string>

The placeholder value of the secret.

value

Type Output<string>

The value of the secret. It’ll be undefined if the secret has not been set through the CLI or if the placeholder hasn’t been set.

The following are accessible through the SDK at runtime.

value

Type string

The value of the secret. It’ll be undefined if the secret has not been set through the CLI or if the placeholder hasn’t been set.