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 badges1 Answer
Reset to default 1In 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
版权声明:本文标题:typescript - How do I read the current stage of SST in a Function (AWS Lambda) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736305041a1932450.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论