admin管理员组

文章数量:1122832

I have an SST project, and I would like to read the current stage in order to determine if the function is running in dev mode/testing mode or production in order to switch some behaviour. My root sst.env.config looks something like this:

export default $config({
  app(input) {
    return {
      name: "my-project",
      removal: input?.stage === "production" ? "retain" : "remove",
      home: "aws",
    };
  },
  async run() {
    // some imports here
    return {
      // some exports here
      Region: aws.getRegionOutput().name,
    };
  },
});

I see in there that I can read the current stage in the "input" parameter of the app function, but I have no idea how I get it out of the SST context into the Lambda context. There is some documentation from SST 2.x that shows you can do it like this:

import { Config } from "sst/node/config";

Config.APP;
Config.STAGE;

But that import no longer works in 3.x, since you are now expected to import your local sst.env.d.ts file, not a dependency. I have also tried to get the stage via the Resource class, but no dice.

Does anyone have an idea on how to do this in SST 3.x?

I have an SST project, and I would like to read the current stage in order to determine if the function is running in dev mode/testing mode or production in order to switch some behaviour. My root sst.env.config looks something like this:

export default $config({
  app(input) {
    return {
      name: "my-project",
      removal: input?.stage === "production" ? "retain" : "remove",
      home: "aws",
    };
  },
  async run() {
    // some imports here
    return {
      // some exports here
      Region: aws.getRegionOutput().name,
    };
  },
});

I see in there that I can read the current stage in the "input" parameter of the app function, but I have no idea how I get it out of the SST context into the Lambda context. There is some documentation from SST 2.x that shows you can do it like this:

import { Config } from "sst/node/config";

Config.APP;
Config.STAGE;

But that import no longer works in 3.x, since you are now expected to import your local sst.env.d.ts file, not a dependency. I have also tried to get the stage via the Resource class, but no dice.

Does anyone have an idea on how to do this in SST 3.x?

Share Improve this question asked Nov 22, 2024 at 8:52 TeaDrinkingProgrammerTeaDrinkingProgrammer 1251 silver badge10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

In your lambda function you can now import Resource from "sst":

import { Resource } from "sst"

console.log(Resource.App.stage)

本文标签: typescriptHow do I read the current stage of SST in a Function (AWS Lambda)Stack Overflow