Skip to main content

Tagging Resources

Tags are key-value metadata that you can add to the resources in your SST app. A tag applied to a given construct and also applies to all of its taggable children. You can use tags to identify and categorize resources to simplify management, control costs, and for access control.

Let's look at how to add tags.

Tagging the app

To add tags to all the resources in your app.

stacks/index.js
import * as cdk from "@aws-cdk/core";

export default function main(app) {
cdk.Tags.of(app).add("my-tag", `${app.stage}-${app.region}`);
}

Tagging the Debug Stack

You can also add tags to the Debug Stack that SST deploys for the Live Lambda Dev environment.

To do that use the debugApp callback method in your stacks/index.js.

stacks/index.js
import * as cdk from "@aws-cdk/core";
import * as sst from "@serverless-stack/resources";

export default function main(app) {
// Define your stacks here
}

export function debugApp(app) {
// Make sure to create the DebugStack when using the debugApp callback
new sst.DebugStack(app, "debug-stack");
cdk.Tags.of(app).add("my-tag", `${app.stage}-${app.region}`);
}
note

If you are using the debugApp callback, you'll need to make sure to create the DebugStack in it.