-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Enable pretty printing using code instead of environment variable #3466
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hi @TeaDrinkingProgrammer, thank you for opening this issue. The pretty printing option has been purposefully added as an environment variable to reduce the chance of developers forgetting to remove it within their code and inadvertently increasing their logging bill. The rationale is that this type of setting should be dependent on where the function is being deployed, which is a concern that the function code itself should not have. Keeping this separate allows you to dynamically change the setting without having to modify your code. As such, I am not sure adding a constructor parameter is a good idea. Based on my understanding of SST, a good place to add this setting could be in your export default $config({
app(input) {
return {
name: 'your-app',
home: 'aws'
}
},
async run() {
const isPersonalStage = $app.stage === 'your-stage-name';
$transform(sst.aws.Function, (args) => {
args.environment = {
...args.environment,
...(isPersonalStage && { POWERTOOLS_DEV: 'true' }),
};
});
}
}) This way you don't have to add the environment variable to every single Function resource you create, and other settings in the resource are left as they are. I took the liberty to shorten the conditional to narrow it down to a single stage name, but you can also use one similar to the one you are already using. |
I have been looking into the SST docs a bit more, and I think there's an even better way to detect if you're running in dev mode from within your That method is pretty much what you're trying to do here and is described in relation to environment variables. Using it would change the code above like this: export default $config({
app(input) {
return {
name: 'your-app',
home: 'aws'
}
},
async run() {
$transform(sst.aws.Function, (args) => {
args.environment = {
...args.environment,
...($dev === true && { POWERTOOLS_DEV: 'true' }),
};
});
}
}) |
I have tried implementing this, and as far as I understand from the docs, this should work, but it doesn't. I have asked in the Discord for help, will report back if I have a snippet to share. |
I have implemented this and I can confirm it works. Not sure if you're already doing this, but this |
I have put the transform before all of my resources, and it does not work, so this is quite interesting. Seems like a bug, but I'm not sure. |
You are right, the only way it works is if I write the transform like this: $transform(sst.aws.Function, (args) => {
args.environment = {
...($dev === true && { POWERTOOLS_DEV: "true" }),
}
}); but in this case it overwrites any other env variable I set in the function/route itself. Looks like a bug, you're right. |
After rereading the Based on what we're seeing it looks like this is not the case, however I can see how this is unintuitive and also limiting in the case of environment variables. Either way, this seems to be a SST issue rather than a Powertools for AWS one - so I'll leave the issue open for a bit longer and resolve it in a few days unless something new comes up. From our side we stand by our decision of keeping the feature outside of the function code and leaving it in the environment. |
Use case
Hi all,
I am very happy with the ability to pretty print locally, but because I am using SST, it would be easier for me to enable devmode in code than to set it as an environment variable. I currently need to do this, which works but feels very hacky:
Solution/User Experience
Something like this would be great:
Alternative solutions
Acknowledgment
Future readers
Please react with 👍 and your use case to help us understand customer demand.
The text was updated successfully, but these errors were encountered: