In the previous chapter, we created a Stripe account and got a pair of keys. Including the Stripe secret key. We need this in our app but we do not want to store this secret in our code. In this chapter, we’ll look at how to add secrets in SST.

We will be using the sst secret CLI to store our secrets.

Change indicator Run the following in your project root.

$ npx sst secret set StripeSecretKey <YOUR_STRIPE_SECRET_TEST_KEY>

You can run npx sst secret list to see the secrets for the current stage.

Now that the secret is stored, we can add it into our config using the Secret component.

Change indicator Add the following to your infra/storage.ts:

// Create a secret for Stripe
export const secret = new sst.Secret("StripeSecretKey");

Change indicator Import secret in infra/api.ts. Replace the following.

import { table } from "./storage";

Change indicator With:

import { table, secret } from "./storage";

Change indicator Next, link StripeSecretKey to the API in infra/api.ts. Replace this:

link: [table],

Change indicator With:

link: [table, secret],

This will add StripeSecretKey in our infrastructure. And allow our API to access the secret.

Now we are ready to add an API to handle billing.