www/src/content/docs/blog/config.mdx
import { YouTube } from '@astro-community/astro-embed-youtube';
We are launching a set of tools to securely manage secrets and environment variables in your SST apps, called Config.
You can read more about it in detail over on our docs. The Config libraries include:
Config.SecretConfig.Parametersst secrets [action]@serverless-stack/node/config
Behind the scenes, Secrets and Parameters are stored as AWS SSM Parameters in your AWS account. They are stored with the Standard Parameter type and Standard Throughput.
This makes Config free to use in your SST apps.
We hosted a launch livestream on YouTube where we did a deep dive of the Config and its internals.
<YouTube id="6sMTfoeshLo" posterQuality="high" />The video is timestamped and here's roughly what we covered.
sst secretsTo get started, define a secret in your stacks.
import { Config, StackContext } from "@serverless-stack/resources";
export default function SecretsStack({ stack }: StackContext) {
const STRIPE_KEY = new Config.Secret(stack, "STRIPE_KEY");
return { STRIPE_KEY };
}
Use the config option to pass the secret into the function.
import { use, Function, StackContext } as sst from "@serverless-stack/resources";
import SecretsStack from "./SecretsStack";
export default function MyStack({ stack }: StackContext) {
const { STRIPE_KEY } = use(SecretsStack);
new Function(stack, "MyFunction", {
handler: "lambda.handler",
config: [STRIPE_KEY],
}
};
In your terminal, run the sst secrets command to set a value for the secret:
$ npx sst secrets set STRIPE_KEY sk_test_abc123
Finally in your function code, use the @serverless-stack/node/config library to reference the secret value:
import { Config } from "@serverless-stack/node/config";
export const handler = async () => {
console.log(Config.STRIPE_KEY);
// ...
};
To learn more check out our docs.