I'm trying to implement a way to dynamically change the log level for my Lambda functions in .NET. I found a suggestion about using AWS Systems Manager (SSM) with Parameter Store to handle this, especially when modifying an environment variable isn't suitable. Is using Parameter Store the right approach, or should I be considering something else? Also, is there a method to force a refresh across Lambda execution environments to apply the new log level immediately, or do I just have to wait for new environments to be created naturally? Thanks for any help!
3 Answers
There's actually a Lambda extension that polls the Parameter Store periodically, which can help you get the latest log level. Check out the docs on AWS for more details. Alternatively, you can set the log level using an environment variable. When you deploy it, it will spin up new instances for new incoming requests while existing ones will finish their current tasks before shutting down, ensuring they use the new settings.
Absolutely, Parameter Store is the right choice here! It’s the go-to for dynamic configuration in AWS. It even provides versioning and encryption, which is a plus for sensitive settings. As for getting all your Lambda instances to pick up the new log level, there isn’t a direct way to force that. Lambda manages its own execution environments, so they spin up based on internal rules. If you want to speed things up a bit, tweaking your function code or settings might trigger some new instances, but it's not a guaranteed solution. Most developers just wait it out for the environments to cycle naturally! 😂
Thanks for the insights! Really appreciate your input!
Changing the environment variable should cause the Lambda runtime to restart, which could enforce a log level change. That said, I don't know of a more straightforward method than that.

You could also consider treating the parameter like a cache that expires. By keeping track of when you last retrieved the parameter, you can re-fetch it after a set time. That way, your log level updates more dynamically.